Submission #36140278
Source Code Expand
#include<bits/stdc++.h> #ifdef xay5421 #define D(...) fprintf(stderr,__VA_ARGS__) #define DD(...) D(#__VA_ARGS__ "="),debug_helper::debug(__VA_ARGS__),D("\n") #include"/home/xay5421/debug.hpp" #else #define D(...) ((void)0) #define DD(...) ((void)0) #endif #define pb push_back #define eb emplace_back #define SZ(x) ((int)(x).size()) #define each(x,v) for(auto&x:v) #define rep(i,a,b) for(int i=(a);i<=(b);++i) #define per(i,a,b) for(int i=(a);i>=(b);--i) template<class T>void rd(T&x){int f=0,c;while(!isdigit(c=getchar()))f^=!(c^45);x=(c&15);while(isdigit(c=getchar()))x=x*10+(c&15);if(f)x=-x;} template<class T>void pt(T x,int c=-1){if(x<0)putchar('-'),x=-x;if(x>9)pt(x/10);putchar(x%10+48);if(c!=-1)putchar(c);} using namespace std; using LL=long long; using ULL=unsigned long long; const int N=100005; int n,a[N],b[N],st[N],top,lc[N],rc[N]; struct node{ map<int,LL>mp; LL s; }tr[N]; void solve(int l,int r,int u,int mx){ if(l>r){ return; } mx=max(mx,a[u]); solve(l,u-1,lc[u],mx); solve(u+1,r,rc[u],mx); if(u-l>r-u){ tr[u]=move(tr[lc[u]]); each(x,tr[rc[u]].mp){ tr[u].mp[x.first]+=x.second; } tr[u].s+=tr[rc[u]].s; while(!tr[u].mp.empty()&&tr[u].mp.begin()->first<=a[u]){ tr[u].s-=tr[u].mp.begin()->second; tr[u].mp.erase(tr[u].mp.begin()); } while(!tr[u].mp.empty()&&tr[u].s>=b[u]){ if(tr[u].s-tr[u].mp.begin()->second>b[u]){ tr[u].s-=tr[u].mp.begin()->second; tr[u].mp.erase(tr[u].mp.begin()); }else{ tr[u].mp.begin()->second-=tr[u].s-b[u]; tr[u].s=b[u]; break; } } tr[u].mp[a[u]]+=b[u]-tr[u].s; tr[u].s=b[u]; }else{ tr[u]=move(tr[rc[u]]); each(x,tr[lc[u]].mp){ tr[u].mp[x.first]+=x.second; } tr[u].s+=tr[lc[u]].s; while(!tr[u].mp.empty()&&tr[u].mp.begin()->first<=a[u]){ tr[u].s-=tr[u].mp.begin()->second; tr[u].mp.erase(tr[u].mp.begin()); } while(!tr[u].mp.empty()&&tr[u].s>=b[u]){ if(tr[u].s-tr[u].mp.begin()->second>b[u]){ tr[u].s-=tr[u].mp.begin()->second; tr[u].mp.erase(tr[u].mp.begin()); }else{ tr[u].mp.begin()->second-=tr[u].s-b[u]; tr[u].s=b[u]; break; } } tr[u].mp[a[u]]+=b[u]-tr[u].s; tr[u].s=b[u]; } } int main(){ rd(n); rep(i,1,n){ rd(a[i]); } rep(i,1,n){ rd(b[i]); } rep(i,1,n){ while(top&&b[i]>b[st[top]]){ lc[i]=st[top--]; } rc[st[top]]=i; st[++top]=i; } solve(1,n,rc[0],0); int last=0; LL cur=tr[rc[0]].s; LL ans=0; each(x,tr[rc[0]].mp){ ans+=1LL*(x.first-last)*cur; cur-=x.second; last=x.first; } printf("%lld\n",ans); return 0; }
Submission Info
Submission Time | |
---|---|
Task | Ex - Monster |
User | xay5421 |
Language | C++ (GCC 9.2.1) |
Score | 600 |
Code Size | 2625 Byte |
Status | AC |
Exec Time | 147 ms |
Memory | 61520 KiB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 600 / 600 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | example_00.txt, example_01.txt, example_02.txt |
All | example_00.txt, example_01.txt, example_02.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, hand_10.txt, hand_11.txt, hand_12.txt, hand_13.txt, hand_14.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
example_00.txt | AC | 9 ms | 9076 KiB |
example_01.txt | AC | 9 ms | 9052 KiB |
example_02.txt | AC | 7 ms | 8916 KiB |
hand_00.txt | AC | 33 ms | 15108 KiB |
hand_01.txt | AC | 26 ms | 15496 KiB |
hand_02.txt | AC | 31 ms | 14696 KiB |
hand_03.txt | AC | 86 ms | 40308 KiB |
hand_04.txt | AC | 77 ms | 40456 KiB |
hand_05.txt | AC | 82 ms | 40300 KiB |
hand_06.txt | AC | 27 ms | 13728 KiB |
hand_07.txt | AC | 33 ms | 16504 KiB |
hand_08.txt | AC | 33 ms | 16876 KiB |
hand_09.txt | AC | 36 ms | 16728 KiB |
hand_10.txt | AC | 31 ms | 16860 KiB |
hand_11.txt | AC | 35 ms | 16760 KiB |
hand_12.txt | AC | 111 ms | 46544 KiB |
hand_13.txt | AC | 48 ms | 20992 KiB |
hand_14.txt | AC | 147 ms | 61520 KiB |
random_00.txt | AC | 40 ms | 15820 KiB |
random_01.txt | AC | 86 ms | 32860 KiB |
random_02.txt | AC | 92 ms | 35664 KiB |
random_03.txt | AC | 35 ms | 14520 KiB |
random_04.txt | AC | 39 ms | 22280 KiB |
random_05.txt | AC | 94 ms | 36344 KiB |
random_06.txt | AC | 43 ms | 15512 KiB |
random_07.txt | AC | 47 ms | 18156 KiB |
random_08.txt | AC | 95 ms | 37328 KiB |
random_09.txt | AC | 34 ms | 23072 KiB |
random_10.txt | AC | 86 ms | 33300 KiB |
random_11.txt | AC | 37 ms | 15100 KiB |
random_12.txt | AC | 41 ms | 15748 KiB |
random_13.txt | AC | 90 ms | 33380 KiB |
random_14.txt | AC | 30 ms | 18508 KiB |
random_15.txt | AC | 35 ms | 14524 KiB |
random_16.txt | AC | 86 ms | 34196 KiB |
random_17.txt | AC | 95 ms | 36932 KiB |
random_18.txt | AC | 39 ms | 15668 KiB |
random_19.txt | AC | 58 ms | 29328 KiB |
random_20.txt | AC | 95 ms | 37340 KiB |
random_21.txt | AC | 39 ms | 15628 KiB |
random_22.txt | AC | 86 ms | 32560 KiB |
random_23.txt | AC | 35 ms | 15104 KiB |
random_24.txt | AC | 29 ms | 16532 KiB |
random_25.txt | AC | 33 ms | 19172 KiB |
random_26.txt | AC | 41 ms | 17808 KiB |
random_27.txt | AC | 35 ms | 15700 KiB |
random_28.txt | AC | 44 ms | 17624 KiB |
random_29.txt | AC | 34 ms | 23576 KiB |
random_30.txt | AC | 34 ms | 14536 KiB |
random_31.txt | AC | 45 ms | 18256 KiB |