# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
619939 |
2022-08-02T17:23:32 Z |
1ne |
Pairs (IOI07_pairs) |
C++14 |
|
440 ms |
524288 KB |
#include<bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int b,n,d,m;cin>>b>>n>>d>>m;
if (b == 1){
vector<int>arr(m + 1,0);
for (int i = 0;i<n;++i){
int a;cin>>a;
arr[a]++;
}
for (int i = 1;i<=m;++i){
arr[i]+=arr[i - 1];
}
long long ans = arr[d] * (arr[d] - 1)/2;
for (int i = d + 1;i<=m;++i){
//cout<<i<<" "<<(arr[i] - arr[i - 1])<<" "<<arr[i - 1] - arr[i - d - 1]<<'\n';
long long pos = (arr[i] - arr[i - 1]) * (arr[i - 1] - arr[i - d - 1]);
ans+=pos;
ans+=(arr[i] - arr[i - 1]) * (arr[i] - arr[i - 1] - 1)/2;
}
cout<<ans<<'\n';
}
else if (b == 2){
vector<vector<int>>brr(m + 1,vector<int>(m + 1,0));
for (int i = 0;i<n;++i){
int a,b;cin>>a>>b;
brr[a][b]++;
}
vector<vector<int>>corner_sum(m + 1,vector<int>(m + 1,-1));
function<int(int,int)>dfs = [&](int i,int j){
if (i < 0 || j > m)return 0;
if (corner_sum[i][j]!=-1)return corner_sum[i][j];
corner_sum[i][j] = brr[i][j] + dfs(i - 1,j + 1);
return corner_sum[i][j];
};
for (int i = 1;i<=m;++i){
for (int j = 0;j<=m;++j){
brr[i][j] +=brr[i - 1][j];
}
}
for (int i = 0;i<=m;++i){
for (int j = 0;j<=m;++j){
dfs(i,j);
}
}
long long ans = 0;
for (int i = 1;i + d<=m;++i){
for (int j = 0;j<=m;++j){
ans+=(corner_sum[i + d][j] - ((i - 1>=0 && j + d + 1<=m)?corner_sum[i - 1][j + d + 1] : 0)) * (brr[i][j] - brr[i - 1][j]);
}
}
cout<<ans<<'\n';
}
else{
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
440 ms |
293780 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
596 KB |
Output is correct |
2 |
Incorrect |
11 ms |
592 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
425 ms |
275144 KB |
Output is correct |
2 |
Incorrect |
301 ms |
275040 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
424 ms |
275084 KB |
Output is correct |
2 |
Correct |
394 ms |
275084 KB |
Output is correct |
3 |
Correct |
410 ms |
275064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
199 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
11 ms |
964 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
34 ms |
9004 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
249 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
328 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |