Submission #1136444

#TimeUsernameProblemLanguageResultExecution timeMemory
1136444KasymKSegments (IZhO18_segments)C++17
0 / 100
5091 ms2500 KiB
#include "bits/stdc++.h" using namespace std; #define ff first #define ss second #define all(v) v.begin(), v.end() #define ll long long #define pb push_back #define pii pair<int, int> #define pli pair<ll, int> #define pll pair<ll, ll> #define tr(i, c) for(auto i = c.begin(); i != c.end(); ++i) #define wr puts("----------------") template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;} template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;} const int N = 2e5+5; vector<pii> v[2], nowv[2]; vector<int> cnt[2], now[2]; pii press[N]; // struct node { // int l, r; // vector<int> val; // } seg[N<<2][4]; // void bld(int x, int l, int r, int ind){ // } // int qry(int x, int l, int r, int val){ // } int solve(int wh, int l, int r, int k){ int sm=0; if(!cnt[wh].empty()) sm+=lower_bound(all(cnt[wh]), k)-cnt[wh].begin(); tr(it, now[wh]) sm+=(*it<k); tr(it, nowv[wh]) sm+=(it->ss-it->ff+1>=k and it->ss<l+k-1 or it->ff>r-k+1); tr(it, v[wh]) sm+=(it->ss-it->ff+1>=k and it->ss<l+k-1 or it->ff>r-k+1); return (int)v[wh].size()+(int)nowv[wh].size()-sm; } int main(){ // freopen("file.txt", "r", stdin); int q, T; scanf("%d%d", &q, &T); int id=0, last_ans=0, pk=sqrt(q*log2(q)/4), jem=0; while(q--){ int op; scanf("%d", &op); if(op==1){ int a, b; scanf("%d%d", &a, &b); int l=(a^(T*last_ans)), r=(b^(T*last_ans)); if(l>r) swap(l, r); press[++id]={l, r}; nowv[0].pb({l, r}), now[0].pb(r-l+1); } else if(op==2){ int Id; scanf("%d", &Id); nowv[1].pb(press[Id]), now[1].pb(press[Id].ss-press[Id].ff+1); } else{ int a, b, k; scanf("%d%d%d", &a, &b, &k); int l=(a^(T*last_ans)), r=(b^(T*last_ans)); if(l>r) swap(l, r); last_ans=solve(0, l, r, k)-solve(1, l, r, k); printf("%d\n", last_ans); } jem++; if(jem==pk){ // nowv => updates in each block (reload in each check point // v => all updates (merge with nowv in each check point) // now => update's lengths in each block (reload in each check point) // cnt => all update's lengths (merge with now in each check point) for(int ad = 0; ad < 2; ++ad){ tr(it, nowv[ad]) v[ad].pb(*it); nowv[ad].clear(); tr(it, now[ad]) cnt[ad].pb(*it); now[ad].clear(); sort(all(cnt[ad])); } // build the merge sort tree here } } return 0; }

Compilation message (stderr)

segments.cpp: In function 'int main()':
segments.cpp:47:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |         scanf("%d%d", &q, &T);
      |         ~~~~~^~~~~~~~~~~~~~~~
segments.cpp:51:22: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |                 scanf("%d", &op);
      |                 ~~~~~^~~~~~~~~~~
segments.cpp:54:30: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |                         scanf("%d%d", &a, &b);
      |                         ~~~~~^~~~~~~~~~~~~~~~
segments.cpp:63:30: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |                         scanf("%d", &Id);
      |                         ~~~~~^~~~~~~~~~~
segments.cpp:68:30: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |                         scanf("%d%d%d", &a, &b, &k);
      |                         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
#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...