# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1019475 | 2024-07-10T22:55:09 Z | vjudge1 | Sails (IOI07_sails) | C++17 | 146 ms | 8164 KB |
#include<bits/stdc++.h> using namespace std; struct segtree{ struct node{ long long sum,mn,lz; node(){mn=sum=lz=0;} } T[1<<18]; void pd(int i,int sz){ T[i].mn+=T[i].lz; T[i].sum+=sz*T[i].lz; if(sz>1)T[i*2].lz+=T[i].lz, T[i*2+1].lz+=T[i].lz; T[i].lz=0; } int walk(int i,int l,int r,int p){ if(l==r)return l; pd(i*2,r-l+2>>1),pd(i*2+1,r-l+1>>1); if(p>=T[i*2].mn) return walk(i*2,l,l+r>>1,p); return walk(i*2+1,l+r+2>>1,r,p); } int atpos(int i,int l,int r,int p){ pd(i,r-l+1);if(l==r)return T[i].mn; if(l+r>>1<p) return atpos(i*2+1,l+r+2>>1,r,p); else return atpos(i*2,l,l+r>>1,p); } long long query(int i,int l,int r,int ll,int rr){ pd(i,r-l+1); if(ll>r||l>rr) return 0; if(ll<=l&&r<=rr) return T[i].lz++,pd(i,r-l+1),T[i].sum; long long ans=query(i*2,l,l+r>>1,ll,rr)+ query(i*2+1,l+r+2>>1,r,ll,rr); T[i].mn=min(T[i*2].mn,T[i*2+1].mn); T[i].sum=T[i*2].sum+T[i*2+1].sum; return ans; } segtree(){T[1].lz=-1;} } ST; int main(){ cin.tie(0)->sync_with_stdio(0); int n; long long ans=0; cin>>n; vector<pair<int,int>>masts(n); for(auto&[h,k]:masts) cin>>h>>k; sort(masts.begin(),masts.end()); for(auto[h,k]:masts){ int y=ST.atpos(1,1,1e5+1,h-k+1); int posl=ST.walk(1,1,1e5+1,y-1); int posr=ST.walk(1,1,1e5+1,y); ans+=ST.query(1,1,1e5+1,posl,h); k-=max(0,h-posl+1); ans+=ST.query(1,1,1e5+1,posr,posr+k-1); } cout<<ans<<'\n'; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 6488 KB | Output is correct |
2 | Correct | 2 ms | 6492 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 6488 KB | Output is correct |
2 | Correct | 3 ms | 6492 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 6488 KB | Output is correct |
2 | Correct | 3 ms | 6492 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 6492 KB | Output is correct |
2 | Correct | 3 ms | 6744 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 6492 KB | Output is correct |
2 | Correct | 4 ms | 6492 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 6744 KB | Output is correct |
2 | Correct | 33 ms | 7004 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 34 ms | 7004 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 63 ms | 7516 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 97 ms | 7772 KB | Output is correct |
2 | Correct | 98 ms | 8024 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 107 ms | 8024 KB | Output is correct |
2 | Correct | 67 ms | 8024 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 146 ms | 8164 KB | Output is correct |
2 | Correct | 98 ms | 8028 KB | Output is correct |