# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
514928 | 2022-01-18T20:06:13 Z | kevin | Sails (IOI07_sails) | C++17 | 92 ms | 2528 KB |
#include <bits/stdc++.h> using namespace std; #define ll long long #define all(x) x.begin(), x.end() #define f first #define s second #define ca(v) for(auto i:v) cout<<i<<" "; #define nl cout<<"\n" const int MAXN = 5e5 + 5; struct BIT { vector<int> f; int n; void init(int N) { f = vector<int>(N+1, 0); n = N;} int lsb(int x) { return x & -x; } void update(int p, int v){ while(p <= n){ f[p] += v; p += lsb(p); } } int query(int p) { int sum = 0; while (p > 0) { sum += f[p]; p -= lsb(p); } return sum; } }; int main() { // ios_base::sync_with_stdio(0); cin.tie(0); if (fopen("input.in", "r")) freopen("input.in", "r", stdin); int n; cin>>n; vector<pair<int, int>> ar; for(int i=0; i<n; i++){ int h, k; cin>>h>>k; ar.push_back({h, k}); } BIT bit; bit.init(100005); sort(ar.begin(), ar.end()); for(int i=0; i<n; i++){ int l = 1; int r = ar[i].f; int v = bit.query(1); int a = ar[i].f; while(l <= r){ int m = (l + r) / 2; if(bit.query(m) == v){ a = m; l=m+1; } else r=m-1; } if(a + ar[i].s > ar[i].f){ bit.update(a+1, 1); bit.update(ar[i].f+1, -1); int res = ar[i].s - (ar[i].f - a); bit.update(1, 1); bit.update(res+1, -1); } else{ bit.update(a+1, 1); bit.update(a+ar[i].s+1, -1); } // for(int j=1; j<6; j++) cout<<bit.query(j)<<" "; // nl; } ll tot = 0; for(int i=1; i<=100000; i++){ int x = bit.query(i); tot += (ll)x * (x-1) / 2; } cout<<tot; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 676 KB | Output is correct |
2 | Correct | 1 ms | 588 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 676 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 672 KB | Output is correct |
2 | Incorrect | 1 ms | 588 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 588 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 716 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 8 ms | 844 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 24 ms | 1380 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 43 ms | 1720 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 81 ms | 2252 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 78 ms | 2364 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 92 ms | 2528 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |