# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
54362 |
2018-07-03T08:49:14 Z |
노영훈(#1472) |
Sails (IOI07_sails) |
C++11 |
|
34 ms |
1748 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MX=100010, inf=2e9, HMX=100000;
int n;
pii P[MX];
int tree[MX];
void upt(int pos, int val){
for(; pos>0; pos-=pos&(-pos))
tree[pos]+=val;
}
void upt(int l, int r, int val){
if(r<l) return;
// cout<<l<<' '<<r<<'\n';
upt(r, val); upt(l-1, -val);
}
int val(int pos){
int res=0;
for(; 0<pos && pos<=HMX; pos+=pos&(-pos))
res+=tree[pos];
return res;
}
int main(){
ios::sync_with_stdio(0); cin.tie(0);
cin>>n;
for(int i=1; i<=n; i++){
int h, a; cin>>h>>a;
P[i]={h,a};
}
sort(P+1, P+n+1, greater<pii>());
for(int i=1; i<=n; i++){
// cout<<i<<' '<<P[i].first<<' '<<P[i].second<<'\n';
int up=P[i].first;
int dn=up-P[i].second+1;
int r=i+1;
while(r<=n && dn<=P[r].first && dn>1){
int h, a; tie(h,a)=P[r];
int x=min(a, dn-1);
a-=x;
dn=dn-x;
P[r]={h,a};
r++;
}
// cout<<up<<' '<<dn<<'\n';
upt(dn, up, 1);
}
ll ans=0;
for(int i=1; i<=HMX; i++){
ll x=val(i);
// cout<<x<<' ';
ans+=x*(x-1)/2;
}
cout<<ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
560 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
560 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
560 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
560 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
624 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
15 ms |
936 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
19 ms |
1108 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
30 ms |
1236 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
32 ms |
1620 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
34 ms |
1748 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |