Submission #521471

#TimeUsernameProblemLanguageResultExecution timeMemory
521471errorgornOsumnjičeni (COCI21_osumnjiceni)C++17
60 / 110
1035 ms84096 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ii pair<ll,ll> #define fi first #define se second #define endl '\n' #define puf push_front #define pof pop_front #define pub push_back #define pob pop_back #define ub upper_bound #define lb lower_bound #define rep(x,s,e) for (auto x=(s)-((s)>(e));x!=(e)-((s)>(e));(s)<(e)?x++:x--) #define all(x) (x).begin(),(x).end() #define sz(x) (int) (x).size() mt19937 rng(177013); struct node{ int s,e,m; int val=0,lazy=0; node *l,*r; node (int _s,int _e){ s=_s,e=_e,m=s+e>>1; if (s!=e){ l=new node(s,m); r=new node(m+1,e); } } void propo(){ if (lazy){ val+=lazy; if (s!=e){ l->lazy+=lazy; r->lazy+=lazy; } lazy=0; } } void update(int i,int j,int k){ if (s==i && e==j) lazy+=k; else{ if (j<=m) l->update(i,j,k); else if (m<i) r->update(i,j,k); else l->update(i,m,k),r->update(m+1,j,k); l->propo(),r->propo(); val=max(l->val,r->val); } } int query(int i,int j){ propo(); if (s==i && e==j) return val; else if (j<=m) return l->query(i,j); else if (m<i) return r->query(i,j); else return max(l->query(i,m),r->query(m+1,j)); } } *root=new node(0,400005); int n,q; ii arr[200005]; int nxt[200005]; int tkd[200005][20]; int main(){ cin.tie(0); cout.tie(0); cin.sync_with_stdio(false); cin>>n; rep(x,1,n+1) cin>>arr[x].fi>>arr[x].se; vector<int> uni; rep(x,1,n+1) uni.pub(arr[x].fi),uni.pub(arr[x].se); sort(all(uni)); unordered_map<int,int> id; rep(x,0,sz(uni)) id[uni[x]]=x; rep(x,1,n+1) arr[x].fi=id[arr[x].fi],arr[x].se=id[arr[x].se]; int curr=n; rep(x,n+1,1){ while (root->query(arr[x].fi,arr[x].se)){ root->update(arr[curr].fi,arr[curr].se,-1); curr--; } root->update(arr[x].fi,arr[x].se,1); nxt[x]=curr+1; } memset(tkd,-1,sizeof(tkd)); rep(x,1,n+1) tkd[x][0]=nxt[x]; rep(y,0,18) rep(x,1,n+1) if (tkd[x][y]!=-1){ tkd[x][y+1]=tkd[tkd[x][y]][y]; } cin>>q; int a,b; while (q--){ cin>>a>>b; int ans=0; rep(x,19,0) if (tkd[a][x]!=-1 && tkd[a][x]<=b){ ans+=(1<<x); a=tkd[a][x]; } cout<<ans+1<<endl; } }

Compilation message (stderr)

Main.cpp: In constructor 'node::node(int, int)':
Main.cpp:29:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   29 |   s=_s,e=_e,m=s+e>>1;
      |               ~^~
#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...