# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
954680 |
2024-03-28T10:32:34 Z |
codefox |
Pairs (IOI07_pairs) |
C++14 |
|
4000 ms |
338232 KB |
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#define ll long long
#define arr array<int, 2>
#pragma GCC optimize("Ofast")
int N = 1<<18;
int M = 1<<17;
int K = 17;
int go(int a, int b, int d, vector<vector<arr>> &bin, vector<int> &counter, vector<vector<int>> &upd)
{
if (bin[a][b][d]==-1)
{
upd[a].push_back(0);
bin[a].push_back({-1, -1});
bin[a][b][d] = counter[a];
counter[a]++;
}
return bin[a][b][d];
}
void update(int a, int b, vector<vector<arr>> &bin, vector<int> &counter, vector<vector<int>> &upd)
{
a += N;
while (a)
{
int curr = 0;
int bb = b;
for (int i = K; i >= 0; i--)
{
upd[a][curr]++;
if (bb>=(1<<i))
{
bb -= 1<<i;
curr = go(a, curr, 1, bin, counter, upd);
}
else curr = go(a, curr, 0, bin, counter, upd);
}
upd[a][curr]++;
a/=2;
}
}
ll ac2d(int a, int curr, int l, int r, int x, int y, vector<vector<arr>> &bin, vector<vector<int>> &upd)
{
if (r <=x || l >= y) return 0;
if (l >= x && r <= y)
{
return upd[a][curr];
}
int m = (l+r)/2;
ll sol = 0;
if (bin[a][curr][0]!=-1) sol += ac2d(a, bin[a][curr][0], l, m, x, y, bin, upd);
if (bin[a][curr][1]!=-1) sol += ac2d(a, bin[a][curr][1], m, r, x, y, bin, upd);
return sol;
}
ll acc(int curr, int l, int r, int a, int b, int x, int y, vector<vector<arr>> &bin, vector<vector<int>> &upd)
{
if (r <=a || l >= b) return 0;
if (l >= a && r <= b)
{
return ac2d(curr, 0, 0, N, x, y, bin, upd);
}
int m = (l+r)/2;
return acc(curr*2, l, m, a, b, x, y, bin, upd)+ acc(curr*2+1, m, r, a, b, x, y, bin, upd);
}
int main()
{
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int b, n, d, m;
cin >> b >> n >> d >> m;
if (b == 1)
{
vector<int> nums(n);
for (int i =0; i < n; i++) cin >> nums[i];
sort(nums.begin(), nums.end());
ll sol = 0;
queue<int> q;
for (int i = 0; i < n; i++)
{
while (q.size() && nums[i]-q.front()> d) q.pop();
sol += q.size();
q.push(nums[i]);
}
cout << sol;
}
else if (b==2)
{
vector<vector<arr>> bin;
vector<int> counter;
vector<vector<int>> upd;
bin.assign(2*N, vector<arr>(1, {-1, -1}));
counter.assign(2*N, 1);
upd.assign(2*N, vector<int>(1, 0));
ll sol = 0;
for (int i = 0; i < n; i++)
{
int x, y;
cin >> x >> y;
sol += acc(1, 0, N, x+y-d, x+y+d+1, y-x+M-d, y-x+M+d+1, bin, upd);
update(x+y, y-x+M, bin, counter, upd);
}
cout << sol;
}
else if (b==3)
{
N = 1<<8;
M = 1<<7;
K = 7;
vector<vector<vector<arr>>> bin(76, vector<vector<arr>>(2*N, vector<arr>(1, {-1, -1})));
vector<vector<int>> counter(76, vector<int>(2*N, 1));
vector<vector<vector<int>>> upd(76, vector<vector<int>>(2*N, vector<int>(1, 0)));
ll sol = 0;
for (int i =0; i < n; i++)
{
int x, y, z;
cin >> x >> y >> z;
for (int j = 0; j <= z; j++)
{
int h = d-(z-j);
if (h <0) continue;
sol += acc(1, 0, N, x+y-h, x+y+h+1, y-x+M-h, y-x+M+h+1, bin[j],upd[j]);
}
for (int j = z+1; j < 76; j++)
{
int h = d-(j-z);
if (h <0) break;
sol += acc(1, 0, N, x+y-h, x+y+h+1, y-x+M-h, y-x+M+h+1, bin[j],upd[j]);
}
update(x+y, y-x+M, bin[z], counter[z], upd[z]);
}
cout << sol;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
860 KB |
Output is correct |
2 |
Correct |
10 ms |
1112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
856 KB |
Output is correct |
2 |
Correct |
16 ms |
1112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
860 KB |
Output is correct |
2 |
Correct |
15 ms |
860 KB |
Output is correct |
3 |
Correct |
15 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
69 ms |
65104 KB |
Output is correct |
2 |
Correct |
67 ms |
65108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
236 ms |
61524 KB |
Output is correct |
2 |
Correct |
196 ms |
61356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
703 ms |
97620 KB |
Output is correct |
2 |
Correct |
644 ms |
97672 KB |
Output is correct |
3 |
Correct |
481 ms |
80444 KB |
Output is correct |
4 |
Correct |
599 ms |
90860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2378 ms |
337820 KB |
Output is correct |
2 |
Correct |
2111 ms |
338232 KB |
Output is correct |
3 |
Correct |
627 ms |
102152 KB |
Output is correct |
4 |
Correct |
575 ms |
92972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
6020 KB |
Output is correct |
2 |
Correct |
12 ms |
5936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
72 ms |
5092 KB |
Output is correct |
2 |
Correct |
413 ms |
5096 KB |
Output is correct |
3 |
Correct |
244 ms |
4952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1509 ms |
23700 KB |
Output is correct |
2 |
Execution timed out |
4083 ms |
20880 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4024 ms |
29908 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |