답안 #339937

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
339937 2020-12-26T11:41:48 Z scales 원숭이와 사과 나무 (IZhO12_apple) C++17
0 / 100
2000 ms 109572 KB
#include <bits/stdc++.h>
/*#ifndef LOCAL_RUN
    #pragma GCC optimize("Ofast")
    #pragma GCC optimize("unroll-loops")
    #pragma GCC optimize("fast-math")
    #pragma GCC target("avx2,tune=native")
#endif*/
using namespace std;
long long kol;
unordered_map <long long,long long> z,sum;
void zam(long long x, long long y,long long m,long long l,long long r)
{
   // cout<<"x="<<x<<" y="<<y<<" l="<<l<<" r="<<r<<" m="<<m<<endl;
    if(z[m]!=0)
    {
        sum[m]=r-l+1;
        z[m]=0;
        z[2*m+1]=1;
        z[2*m+2]=1;
    }

    if(x<=l && y>=r)
    {
        //cout<<" obrab"<<endl;
        z[m]=1;
        sum[m]=r-l+1;
    }
    else
    {
        if(x>r || y<l)
        {
            return;
        }
        else
        {
            zam(x,y,2*m+1,l,(l+r)/2);
            zam(x,y,2*m+2,(l+r)/2+1,r);
            sum[m]=sum[2*m+1]+sum[2*m+2];
        }
    }
}



void viv(long long x, long long y,long long m,long long l,long long r)
{
    //cout<<"x="<<x<<" y="<<y<<" l="<<l<<" r="<<r<<" kol="<<kol<<endl;
    if(z[m]!=0)
    {
        //cout<<"aaaaaaa"<<endl;
        sum[m]=r-l+1;
        z[m]=0;
        z[2*m+1]=1;
        z[2*m+2]=1;
    }
    if(x<=l && y>=r)
    {
        kol=kol+sum[m];
        //cout<<"sum[m]="<<sum[m]<<endl;
    }
    else
    {
        if(x>r || y<l)
        {

        }
        else
        {
            viv(x,y,2*m+1,l,(l+r)/2);
            viv(x,y,2*m+2,(l+r)/2+1,r);
            sum[m]=sum[2*m+1]+sum[2*m+2];
        }
    }
}
int main()
{
      ios::sync_with_stdio(false);
      cin.tie(0);
     // freopen("input.txt","r",stdin);
     // freopen("output.txt","w",stdout);
     long long t,i,j,w,dno,mini,x,y,q,m,k,v,n,x1,tip,g,maxi,p,l,r;
     cin>>m;
     vector<long long> st(31);
     st[0]=1;
     for(i=1;i<=30;i++)
     {
         st[i]=st[i-1]*2;
     }
     kol=0;
     for(i=0;i<m;i++)
     {
         cin>>tip;
         cin>>x;
         cin>>y;
         x=x+kol;
         y=y+kol;
         x--;
         y--;
         l=0;
         r=st[30]-1;
         if(tip==2)
         {
            zam(x,y,0,l,r);
         }
         else
         {
                //cout<<"kol="<<kol<<endl;
             kol=0;
            viv(x,y,0,l,r);
            cout<<kol<<endl;
         }
     }
    return 0;
}

Compilation message

apple.cpp: In function 'int main()':
apple.cpp:81:16: warning: unused variable 't' [-Wunused-variable]
   81 |      long long t,i,j,w,dno,mini,x,y,q,m,k,v,n,x1,tip,g,maxi,p,l,r;
      |                ^
apple.cpp:81:20: warning: unused variable 'j' [-Wunused-variable]
   81 |      long long t,i,j,w,dno,mini,x,y,q,m,k,v,n,x1,tip,g,maxi,p,l,r;
      |                    ^
apple.cpp:81:22: warning: unused variable 'w' [-Wunused-variable]
   81 |      long long t,i,j,w,dno,mini,x,y,q,m,k,v,n,x1,tip,g,maxi,p,l,r;
      |                      ^
apple.cpp:81:24: warning: unused variable 'dno' [-Wunused-variable]
   81 |      long long t,i,j,w,dno,mini,x,y,q,m,k,v,n,x1,tip,g,maxi,p,l,r;
      |                        ^~~
apple.cpp:81:28: warning: unused variable 'mini' [-Wunused-variable]
   81 |      long long t,i,j,w,dno,mini,x,y,q,m,k,v,n,x1,tip,g,maxi,p,l,r;
      |                            ^~~~
apple.cpp:81:37: warning: unused variable 'q' [-Wunused-variable]
   81 |      long long t,i,j,w,dno,mini,x,y,q,m,k,v,n,x1,tip,g,maxi,p,l,r;
      |                                     ^
apple.cpp:81:41: warning: unused variable 'k' [-Wunused-variable]
   81 |      long long t,i,j,w,dno,mini,x,y,q,m,k,v,n,x1,tip,g,maxi,p,l,r;
      |                                         ^
apple.cpp:81:43: warning: unused variable 'v' [-Wunused-variable]
   81 |      long long t,i,j,w,dno,mini,x,y,q,m,k,v,n,x1,tip,g,maxi,p,l,r;
      |                                           ^
apple.cpp:81:45: warning: unused variable 'n' [-Wunused-variable]
   81 |      long long t,i,j,w,dno,mini,x,y,q,m,k,v,n,x1,tip,g,maxi,p,l,r;
      |                                             ^
apple.cpp:81:47: warning: unused variable 'x1' [-Wunused-variable]
   81 |      long long t,i,j,w,dno,mini,x,y,q,m,k,v,n,x1,tip,g,maxi,p,l,r;
      |                                               ^~
apple.cpp:81:54: warning: unused variable 'g' [-Wunused-variable]
   81 |      long long t,i,j,w,dno,mini,x,y,q,m,k,v,n,x1,tip,g,maxi,p,l,r;
      |                                                      ^
apple.cpp:81:56: warning: unused variable 'maxi' [-Wunused-variable]
   81 |      long long t,i,j,w,dno,mini,x,y,q,m,k,v,n,x1,tip,g,maxi,p,l,r;
      |                                                        ^~~~
apple.cpp:81:61: warning: unused variable 'p' [-Wunused-variable]
   81 |      long long t,i,j,w,dno,mini,x,y,q,m,k,v,n,x1,tip,g,maxi,p,l,r;
      |                                                             ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 172 ms 12248 KB Output is correct
5 Correct 224 ms 14168 KB Output is correct
6 Correct 209 ms 13784 KB Output is correct
7 Correct 213 ms 14168 KB Output is correct
8 Execution timed out 2087 ms 109572 KB Time limit exceeded
9 Halted 0 ms 0 KB -