# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
291167 |
2020-09-04T19:52:55 Z |
couplefire |
Sails (IOI07_sails) |
C++17 |
|
88 ms |
6904 KB |
#include <bits/stdc++.h>
using namespace std;
int prefix[100005] = {0};
set<int> nextPos;
set<int> prevPos;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
// freopen("a.in", "r", stdin);
int n; cin >> n;
pair<int, int> arr[n];
for(int i = 0; i<n; i++) cin >> arr[i].first >> arr[i].second;
sort(arr, arr+n);
int cur = 100005;
nextPos.insert(cur);
prevPos.insert(-cur);
for(auto p : arr){
int height = p.first, num = p.second;
cur = 100005-height;
prefix[cur]++;
nextPos.insert(cur);
prevPos.insert(-cur);
if(cur+num == 100005) continue;
prefix[cur+num]--;
if(prefix[cur+num] == 0) nextPos.erase(cur+num), prevPos.erase(-cur-num);
if(prefix[cur+num] == -1){
int npos = *nextPos.lower_bound(cur+num);
int ppos = -*prevPos.lower_bound(-cur-num);
if(npos != 100005){
prefix[npos]--;
if(prefix[npos] == 0) nextPos.erase(npos), prevPos.erase(-npos);
}
prefix[ppos]--;
if(prefix[ppos] == 0) nextPos.erase(ppos), prevPos.erase(-ppos);
prefix[cur+num] = 0;
prefix[npos+ppos-cur-num] = 1;
nextPos.insert(npos+ppos-cur-num);
prevPos.insert(-npos-ppos+cur+num);
}
// cout << height << " " << num << endl;
// int cnum = 0;
// for(int i = cur; i<100005; i++){
// cnum += prefix[i];
// cout << cnum << " ";
// }
// cout << endl;
}
long long ans = 0;
int cnum = 0;
for(int i = cur; i<100005; i++){
cnum += prefix[i];
ans += cnum*(cnum-1)/2;
}
cout << ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
512 KB |
Output is correct |
2 |
Correct |
1 ms |
768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
768 KB |
Output is correct |
2 |
Correct |
18 ms |
1024 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
3840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
2424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
2652 KB |
Output is correct |
2 |
Correct |
57 ms |
3704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
71 ms |
6904 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
88 ms |
3832 KB |
Output is correct |
2 |
Correct |
40 ms |
2168 KB |
Output is correct |