# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
279697 | 2020-08-22T09:56:58 Z | patrikpavic2 | Pairs (IOI07_pairs) | C++17 | 50 ms | 2156 KB |
#include <cstdio> #include <cstring> #include <vector> #include <algorithm> #define X first #define Y second #define PB push_back using namespace std; typedef long long ll; typedef pair < int, int > pii; const int N = 3e5 + 500; const int OFF = 1e5 + 500; const int M = 80; int loga[N], B, n, m, D; inline int trans(int x){ return max(min(x + OFF, N - 1), 0); } void add(int x, int y){ x = trans(x); for(; x < N ; x += x & -x) loga[x] += y; } int query(int x){ int ret = 0; x = trans(x); for(; x ; x -= x & -x) ret += loga[x]; return ret; } int main(){ scanf("%d%d%d%d", &B, &n, &D, &m); if(B == 1){ vector < int > v; for(int i = 0;i < n;i++){ int x; scanf("%d", &x); v.PB(x); } sort(v.begin(), v.end()); int l = 0, r = 0, cur = 0; ll sol = 0; for(int i = 0;i < n;i++){ while(v[i] - v[l] > D) cur--, l++; while(r < n && v[r] - v[i] <= D) cur++, r++; sol += cur; } printf("%lld\n", (sol - n) / 2); } if(B == 2){ vector < pii > v; for(int i = 0;i < n;i++){ int x, y; scanf("%d%d", &x, &y); v.PB({x + y, x - y}); } sort(v.begin(), v.end()); int l = 0, r = 0; ll sol = 0; for(int i = 0;i < n;i++){ while(v[i].X - v[l].X > D) add(v[l++].Y, -1); while(r < n && v[r].X - v[i].X <= D) add(v[r++].Y, 1); sol += query(v[i].Y + D) - query(v[i].Y - D - 1); } printf("%lld\n", (sol - n) / 2); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 256 KB | Output is correct |
2 | Correct | 1 ms | 256 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 256 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 1404 KB | Output is correct |
2 | Correct | 20 ms | 1396 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 30 ms | 1660 KB | Output is correct |
2 | Correct | 27 ms | 1788 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 32 ms | 1660 KB | Output is correct |
2 | Correct | 29 ms | 1660 KB | Output is correct |
3 | Correct | 26 ms | 1660 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 896 KB | Output is correct |
2 | Correct | 1 ms | 896 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 39 ms | 1656 KB | Output is correct |
2 | Correct | 36 ms | 1716 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 48 ms | 1656 KB | Output is correct |
2 | Correct | 49 ms | 1656 KB | Output is correct |
3 | Correct | 44 ms | 1656 KB | Output is correct |
4 | Correct | 42 ms | 1656 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 50 ms | 2156 KB | Output is correct |
2 | Correct | 48 ms | 2152 KB | Output is correct |
3 | Correct | 48 ms | 2156 KB | Output is correct |
4 | Correct | 47 ms | 2156 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 256 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 256 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 256 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 256 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |