zoukankan      html  css  js  c++  java
  • cf 755D. PolandBall and Polygon

    题意:把一个多边形往里面连对角线,然后问每次添加多边形被划分为几个部分

    产生的部分就是新加对角线与原有对角线相交条数+1,用线段树(大雾)维护一下。

     1 #include<bits/stdc++.h> 
     2 #define LL long long 
     3 #define N 100005
     4 #define lowbit(x) x&(-x)
     5 using namespace std;
     6 inline LL ra()
     7 {
     8     LL x=0,f=1; char ch=getchar();
     9     while (ch<'0' || ch>'9') {if (ch=='-') f=-1; ch=getchar();}
    10     while (ch>='0' && ch<='9') {x=x*10+ch-'0'; ch=getchar();}
    11     return x*f;
    12 }
    13 LL n,k;
    14 struct node{
    15     LL tag,sum,l,r;
    16 }t[N<<6];
    17 LL T,ans=1;
    18 void build(LL k, LL l, LL r)
    19 {
    20     t[k].l=l; t[k].r=r;
    21     if (l==r) return;
    22     LL mid=l+r>>1;
    23     build(k<<1,l,mid); build(k<<1|1,mid+1,r);
    24 }
    25 void update(LL k)
    26 {
    27     t[k].sum=t[k<<1].sum+t[k<<1|1].sum;
    28 }
    29 void pushdown(LL k)
    30 {
    31     LL tmp=t[k].tag; t[k].tag=0;
    32     t[k<<1].tag+=tmp; t[k<<1|1].tag+=tmp;
    33     t[k<<1].sum+=(t[k<<1].r-t[k<<1].l+1)*tmp;
    34     t[k<<1|1].sum+=(t[k<<1|1].r-t[k<<1|1].l+1)*tmp;
    35 }
    36 void change(LL k, LL x, LL y, LL val)
    37 {
    38     if (x>y || y>n) return;
    39     LL l=t[k].l,r=t[k].r;
    40     if (l==x && y==r)
    41     {
    42         t[k].tag+=val;
    43         t[k].sum+=(r-l+1)*val;
    44         return;
    45     }
    46     if (t[k].tag) pushdown(k);
    47     LL mid=l+r>>1;
    48     if (y<=mid) change(k<<1,x,y,val);
    49     else if (x>mid) change(k<<1|1,x,y,val);
    50     else{
    51         change(k<<1,x,mid,val);
    52         change(k<<1|1,mid+1,y,val);
    53     }
    54     update(k);
    55 }
    56 LL ask(LL k, LL x, LL y)
    57 {
    58     if (x>y || y>n) return 0;
    59     LL l=t[k].l,r=t[k].r;
    60     if (x==l && y==r) return t[k].sum;
    61     if (t[k].tag) pushdown(k);
    62     LL mid=l+r>>1;
    63     if (y<=mid) return ask(k<<1,x,y);
    64     else if (x>mid) return ask(k<<1|1,x,y);
    65     else return ask(k<<1,x,mid)+ask(k<<1|1,mid+1,y);
    66 }
    67 int main()
    68 {
    69     LL last=1,aim;
    70     T=n=ra(); k=ra();
    71     if (k>n/2) k=n-k; 
    72     build(1,1,n);
    73     while (T--)
    74     {    
    75         LL aim=(last+k-1)%n+1;
    76         if (aim>last)
    77         {
    78             ans+=ask(1,last+1,aim-1)+1;
    79             change(1,last,last,1);
    80             change(1,aim,aim,1);
    81         }
    82         else 
    83         {
    84             ans+=ask(1,last+1,n)+ask(1,1,aim-1)+1;
    85             change(1,last,last,1); change(1,aim,aim,1);
    86         }
    87         last=aim;
    88         printf("%I64d ",ans);
    89     //    cout<<ask(2); system("pause");
    90     } 
    91     return 0;
    92 }
  • 相关阅读:
    struts2简介
    HDU 2842 Chinese Rings(矩阵高速功率+递归)
    Cocos2d-X中国象棋的发展《五岁以下儿童》摆棋
    【Python注意事项】如何理解python中间generator functions和yield表情
    [CSS] Design for Mobile First with Tachyons
    [Angular] Configurable NgModules
    [Angular] Using useExisting provider
    [Angular] Providers and useFactory
    [Angular] Using InjectionToken
    [Angular] Test Directive
  • 原文地址:https://www.cnblogs.com/ccd2333/p/6366156.html
Copyright © 2011-2022 走看看