# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
879880 | 2023-11-28T09:02:50 Z | noyancanturk | Sails (IOI07_sails) | C++17 | 27 ms | 8020 KB |
#ifndef Local #pragma GCC optimize("O3,unroll-loops") const int lim=1e5+100; #else const int lim=3e3+100; #endif #include <bits/stdc++.h> using namespace std; #define int long long #define pb push_back const int mod=998244353; using pii=pair<int,int>; struct BIT{ int n,tree[lim]; BIT(); BIT(int n):n(n){ memset(tree,0,sizeof(int)*(n+1)); } BIT(int n,int*ref){ memset(tree,0,sizeof(int)*(n+1)); for(int i=1;i<=n;i++){ tree[i]+=ref[i]; if(i+(i&-i)<=n)tree[i+(i&-i)]+=tree[i]; } } inline void update(int p,int val){ while(p<=n){ tree[p]+=val; p+=p&-p; } } inline int query(int p){ int res=0; while(p){ res+=tree[p]; p-=p&-p; } return res; } }; struct RangeBIT{ BIT a,b; RangeBIT(int n):a(n),b(n){} inline void update(int l,int r,int x){ a.update(l,x); a.update(r+1,-x); b.update(l,x*(l-1)); b.update(r+1,-x*r); } inline void update(int p,int x){ update(p,p,x); } inline int sumy(int p){ return p * a.query(p) - b.query(p); } inline int query(int l,int r){ return sumy(r)-sumy(l-1); } inline int query(int p){ return query(p,p); } }; void solve(){ int n; cin>>n; pii mast[n]; for(int i=0;i<n;i++){ cin>>mast[i].first>>mast[i].second; } sort(mast,mast+n); RangeBIT bit(lim); for(int i=0;i<n;i++){ auto [len,toget]=mast[i]; int indy=len-toget+1; int maxval=bit.query(indy); int l=1,r=len,firstind=-1; while(l<=r){ int mid=(l+r)>>1; //cerr<<l<<" "<<mid<<" "<<r<<"\n"; int valy=bit.query(mid); if(valy<maxval){ r=mid-1; }else if(maxval<valy){ l=mid+1; }else{ firstind=mid; l=mid+1; } } //cerr<<firstind+1<<" "<<len<<"\n"; bit.update(firstind+1,len,1); toget-=len-firstind; l=1,r=firstind; int lastind=-1; while(l<=r){ int mid=(l+r)>>1; //cerr<<l<<" "<<mid<<" "<<r<<"\n"; int valy=bit.query(mid); if(valy<maxval){ r=mid-1; }else if(maxval<valy){ l=mid+1; }else{ lastind=mid; r=mid-1; } } bit.update(lastind,lastind+toget-1,1); /* for(int i=1;i<=10;i++){ cerr<<bit.query(i)<<" "; } */ //cerr<<"\n"; //cerr<<"ok\n"; } int ans=0; for(int i=1;i<lim;i++){ int k=bit.query(i); ans+=k*(k-1)/2; } cout<<ans<<"\n"; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); #ifdef Local freopen(".in","r",stdin); freopen(".out","w",stdout); #else //freopen("optmilk.in","r",stdin); //freopen("optmilk.out","w",stdout); #endif int t=1; //cin>>t; while (t--) { solve(); } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 3 ms | 3672 KB | Execution killed with signal 6 |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 3 ms | 3676 KB | Execution killed with signal 6 |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 3 ms | 3676 KB | Execution killed with signal 6 |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 3 ms | 3672 KB | Execution killed with signal 6 |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 3 ms | 3676 KB | Execution killed with signal 6 |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 4 ms | 3932 KB | Execution killed with signal 6 |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 10 ms | 4900 KB | Execution killed with signal 6 |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 13 ms | 5720 KB | Execution killed with signal 6 |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 19 ms | 7004 KB | Execution killed with signal 6 |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 21 ms | 7516 KB | Execution killed with signal 6 |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 27 ms | 8020 KB | Execution killed with signal 6 |
2 | Halted | 0 ms | 0 KB | - |