Submission #563882

#TimeUsernameProblemLanguageResultExecution timeMemory
563882errorgornTwo Dishes (JOI19_dishes)C++17
0 / 100
883 ms171608 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 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); 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,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+1){ if (drr[0][x]){ root->update1(0,drr[0][x]-1,crr[0][x]); int val=root->query(drr[0][x]-1); int lo=drr[0][x]-1,hi=1000006,mi; while (hi-lo>1){ mi=hi+lo>>1; if (val<=root->query(mi)) hi=mi; else lo=mi; } if (lo!=drr[0][x]-1) root->update2(drr[0][x],lo,val); } while (!idx.empty() && drr[1][idx.back()]==x){ int u=idx.back(); idx.pob(); root->update1(u,1000005,crr[1][u]); } //rep(x,0,m+1) cout<<root->query(x)<<" "; cout<<endl; } cout<<root->val<<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;
      |               ~^~
dishes.cpp: In function 'int main()':
dishes.cpp:138:10: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  138 |     mi=hi+lo>>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...