Submission #626100

#TimeUsernameProblemLanguageResultExecution timeMemory
626100errorgornRadio Towers (IOI22_towers)C++17
56 / 100
1475 ms79852 KiB
#include "towers.h" #include <bits/stdc++.h> using namespace std; #define int long long #define ii pair<int,int> #define fi first #define se second #define puf push_front #define pof pop_front #define pub push_back #define pob pop_back #define lb lower_bound #define ub upper_bound #define rep(x,s,e) for (int 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(chrono::system_clock::now().time_since_epoch().count()); struct dat{ int mn,mx; int a,b; dat(){}; dat (int i){ mn=mx=i; a=b=0; } }; dat merge(dat a,dat b){ dat res; res.mn=min(a.mn,b.mn); res.mx=max(a.mx,b.mx); res.a=max({a.a,b.a,a.mx-b.mn}); res.b=max({a.b,b.b,b.mx-a.mn}); return res; } struct node{ int s,e,m; dat val; 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 update(int i,int k){ if (s==e) val=dat(k); else{ if (i<=m) l->update(i,k); else r->update(i,k); val=merge(l->val,r->val); } } dat query(int i,int j){ 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 merge(l->query(i,m),r->query(m+1,j)); } } *root=new node(0,100005); int n; int arr[100005]; void init(signed N, vector<signed> H) { n=N; rep(x,0,n) arr[x+1]=H[x]; rep(x,1,n+1) root->update(x,arr[x]); } bool proc=false; ii tkd[200005][20]; //(nxt,score) signed max_towers(signed l, signed r, signed d) { if (l==r) return 1; l++,r++; //0-based indexing is cringe if (!proc){ memset(tkd,-1,sizeof(tkd)); int r=n+1; rep(x,n+1,1){ while (x<r && root->query(x,r-1).a>=d) r--; if (r!=n+1) tkd[x*2][0]={2*r+1,1}; } r=n+1; rep(x,n+1,1){ while (x<r && root->query(x,r-1).b>=d) r--; if (r!=n+1) tkd[x*2+1][0]={2*r,0}; } rep(layer,0,19){ rep(x,0,200005) if (tkd[x][layer].fi!=-1){ int nxt=tkd[x][layer].fi; if (tkd[nxt][layer].fi==-1) continue; tkd[x][layer+1]={tkd[nxt][layer].fi,tkd[x][layer].se+tkd[nxt][layer].se}; } } proc=true; } int curr=l*2+1; int ans=1; rep(x,20,0){ if (tkd[curr][x].fi!=-1 && tkd[curr][x].fi/2<=r){ ans+=tkd[curr][x].se; curr=tkd[curr][x].fi; } } return ans; }

Compilation message (stderr)

towers.cpp: In constructor 'node::node(long long int, long long int)':
towers.cpp:51:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   51 |   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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...