Submission #563894

#TimeUsernameProblemLanguageResultExecution timeMemory
563894errorgornTwo Dishes (JOI19_dishes)C++17
74 / 100
6186 ms229764 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define ii pair<int,int> #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 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::steady_clock::now().time_since_epoch().count()); const int INF=1e18; int n,m; int arr[2][1000005]; int brr[2][1000005]; int crr[2][1000005]; int drr[2][1000005]; struct node{ int s,e,m; int val=0; //stores the max value int lazy=0; bool lazyt=false; //false = increment, true = set 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 (lazyt){ val=lazy; if (s!=e){ l->lazy=r->lazy=lazy; l->lazyt=r->lazyt=true; } } else if (lazy){ val+=lazy; if (s!=e){ l->lazy+=lazy; r->lazy+=lazy; } } lazy=0; lazyt=false; } void update1(int i,int j,int k){ propo(); if (s==i && e==j) lazy+=k; else{ if (j<=m) l->update1(i,j,k); else if (m<i) r->update1(i,j,k); else l->update1(i,m,k),r->update1(m+1,j,k); l->propo(),r->propo(); val=max(l->val,r->val); } } void update2(int i,int j,int k){ propo(); if (s==i && e==j){ lazy=k; lazyt=true; } else{ if (j<=m) l->update2(i,j,k); else if (m<i) r->update2(i,j,k); else l->update2(i,m,k),r->update2(m+1,j,k); l->propo(),r->propo(); val=max(l->val,r->val); } } int getr(int i,int k){ propo(); if (val<k) return -1; if (s==e) return s; if (m<i) return r->getr(i,k); else{ int temp=l->getr(i,k); if (temp!=-1) return temp; else return r->getr(i,k); } } int query(int i){ propo(); if (s==e) return val; else if (i<=m) return l->query(i); else return r->query(i); } } *root=new node(0,1000005); void expand(int i){ int val=root->query(i); int temp=root->getr(i+1,val); if (temp==-1) root->update2(i+1,1000005,val); else if (temp!=i+1) root->update2(i+1,temp-1,val); } signed main(){ cin.tie(0); cout.tie(0); cin.sync_with_stdio(false); cin>>n>>m; rep(x,1,n+1) cin>>arr[0][x]>>brr[0][x]>>crr[0][x]; rep(x,1,m+1) cin>>arr[1][x]>>brr[1][x]>>crr[1][x]; rep(x,1,n+1) arr[0][x]+=arr[0][x-1]; rep(x,1,m+1) arr[1][x]+=arr[1][x-1]; //rep(x,0,n+1) cout<<arr[0][x]<<" "; cout<<endl; rep(x,1,n+1) drr[0][x]=ub(arr[1],arr[1]+m+1,brr[0][x]-arr[0][x])-arr[1]; rep(x,1,m+1) drr[1][x]=ub(arr[0],arr[0]+n+1,brr[1][x]-arr[1][x])-arr[0]; //rep(x,1,n+1) cout<<drr[0][x]<<" "; cout<<endl; //rep(x,1,m+1) cout<<drr[1][x]<<" "; cout<<endl; vector<int> idx; rep(x,1,m+1) if (drr[1][x]) idx.pub(x); sort(all(idx),[](int i,int j){ return drr[1][i]>drr[1][j]; }); rep(x,1,n+2){ vector<int> pos; while (!idx.empty() && drr[1][idx.back()]==x){ int u=idx.back(); idx.pob(); root->update1(u,1000005,crr[1][u]); //we cannot expand here pos.pub(u-1); } if (x!=n+1 && drr[0][x]){ root->update1(0,drr[0][x]-1,crr[0][x]); pos.pub(drr[0][x]-1); } sort(all(pos)); for (auto it:pos) expand(it); } cout<<root->query(m)<<endl; }

Compilation message (stderr)

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