제출 #898506

#제출 시각아이디문제언어결과실행 시간메모리
898506DenkataSegments (IZhO18_segments)C++14
100 / 100
2174 ms17044 KiB
///mnogo trqbva da se vnimava s lower/upperbound queryta v pair #include<bits/stdc++.h> using namespace std; const int maxn = 2e5+3; const int crit = 2000; int i,j,p,q,n,m,k,L,R,A,B,lans,id,lb[maxn],rb[maxn],block[maxn],minlen[maxn],t,curlen; vector < pair <int,int> > cur,all; vector < pair <int,int> > levi[100],desni[100];//n/crit int removed[maxn]; void insert(int l,int r,int nom) { cur.push_back({r-l+1,nom}); if(cur.size()==crit) { vector <pair <int,int>> neww; for(i=0; i<=all.size()/crit+2; i++) levi[i].clear(),desni[i].clear(),minlen[i] = -1; for(auto i:cur) neww.push_back(i); for(auto i:all) neww.push_back(i); cur.clear(); all.clear(); for(auto i:neww) { if(!removed[i.second]) all.push_back(i); } ///build the structure sort(all.rbegin(),all.rend()); int bl = 0; int br = 0; int Min = INT_MAX; for(auto i:all) { levi[bl].push_back({lb[i.second],i.second}); desni[bl].push_back({rb[i.second],i.second}); Min = min(Min,i.first); block[i.second] = bl; br++; if(br==crit) { minlen[bl] = Min; Min = INT_MAX; bl++; br = 0; } } for(i=0; i<=all.size()/crit+2; i++) { if(levi[i].empty())break; sort(levi[i].begin(),levi[i].end()); sort(desni[i].begin(),desni[i].end()); } } } void remove(int id) { removed[id] = true; if(block[id]==-1) { vector < pair <int,int> > newws; for(auto i:cur) if(i.second!=id)newws.push_back(i); cur = newws; return ; } p = block[id]; vector < pair <int,int> > newws; for(auto i:levi[p]) if(i.second!=id)newws.push_back(i); levi[p] = newws; newws.clear(); for(auto i:desni[p]) if(i.second!=id)newws.push_back(i); desni[p] = newws; block[id] = -1; } int solve(int l,int r,int k) { int ans = 0; for(auto i:cur) { //cout<<lb[i.second]<<" "<<rb[i.second]<<" "<<l<<" "<<r<<" "<<k<<endl; if(min(rb[i.second],r)-max(lb[i.second],l)+1>=k) ans++; } for(i=0; i<=all.size()/crit+1; i++) { if(levi[i].empty())continue; if(minlen[i]<k) { ///iterative check j = i; for(auto i:levi[j]) { if(removed[i.second]) continue; if(min(rb[i.second],r)-max(lb[i.second],l)+1>=k) ans++; } break; } ans+=levi[i].size(); p = 0; ///indexed from 0 p += upper_bound(desni[i].begin(),desni[i].end(), make_pair(l+k-2,10000000))-desni[i].begin(); p += levi[i].size()-(lower_bound(levi[i].begin(),levi[i].end(), make_pair(r-k+2,-1))-levi[i].begin()); ans-=p; } return ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin>>n>>t; for(i=0; i<=n; i++) block[i] = -1,minlen[i] = -1; lans = 0; while(n--) { int type; cin>>type; if(type==1) { cin>>A>>B; L = A^(t*lans); R = B^(t*lans); if(L>R)swap(L,R); curlen++; lb[curlen] = L; rb[curlen] = R; insert(L,R,curlen); } else if(type==2) { cin>>id; remove(id); } else { cin>>A>>B>>k; L = A^(t*lans); R = B^(t*lans); if(L>R)swap(L,R); lans = solve(L,R,k); cout<<lans<<endl; } } return 0; } /** 6 1 1 1 2 3 2 4 2 1 3 5 3 2 3 1 2 1 3 0 3 1 6 0 1 3 10 1 3 5 3 6 10 6 2 1 1 3 10 3 6 4 2 */

컴파일 시 표준 에러 (stderr) 메시지

segments.cpp: In function 'void insert(int, int, int)':
segments.cpp:17:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |         for(i=0; i<=all.size()/crit+2; i++)
      |                  ~^~~~~~~~~~~~~~~~~~~
segments.cpp:52:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |         for(i=0; i<=all.size()/crit+2; i++)
      |                  ~^~~~~~~~~~~~~~~~~~~
segments.cpp: In function 'int solve(int, int, int)':
segments.cpp:94:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |     for(i=0; i<=all.size()/crit+1; i++)
      |              ~^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...