# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
988413 |
2024-05-24T16:16:08 Z |
huutuan |
Pairs (IOI07_pairs) |
C++14 |
|
93 ms |
10320 KB |
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long
const int N=1e5+10;
int b, n, d, m;
namespace sub1{
int a[N];
void solve(){
for (int i=1; i<=n; ++i) cin >> a[i];
sort(a+1, a+n+1);
int ans=0;
for (int i=1, j=1; i<=n; ++i){
while (a[i]-a[j]>d) ++j;
ans+=i-j;
}
cout << ans << '\n';
}
}
const int inf=1e9;
namespace sub2{
pair<int, int> a[N];
void solve(){
for (int i=1; i<=n; ++i){
int x, y; cin >> x >> y;
a[i]={x+y, x-y};
}
sort(a+1, a+n+1);
int ans=0;
ordered_set<pair<int, int>> st;
for (int i=1, j=1; i<=n; ++i){
while (a[i].first-a[j].first>d){
st.erase({a[j].second, j});
++j;
}
ans+=st.order_of_key({a[i].second+d+1, -inf})-st.order_of_key({a[i].second-d, -inf});
st.insert({a[i].second, i});
}
cout << ans << '\n';
}
}
namespace sub3{
vector<pair<int, int>> a[N];
int pfsum[151][151];
void prefix_sum(){
for (int i=1; i<=150; ++i) for (int j=1; j<=150; ++j) pfsum[i][j]+=pfsum[i-1][j]+pfsum[i][j-1]-pfsum[i-1][j-1];
}
int get(int x, int y, int z, int t){
x=max(x, 1ll); y=max(y, 1ll); z=min(z, 150ll); t=min(t, 150ll);
return pfsum[z][t]-pfsum[z][y-1]-pfsum[x-1][t]+pfsum[x-1][y-1];
}
void solve(){
for (int i=1; i<=n; ++i){
int x, y, z; cin >> x >> y >> z;
a[x].emplace_back(y+z, y-z+75);
}
for (int i=1; i<=75; ++i) sort(a[i].begin(), a[i].end());
int ans=0;
for (int i=1; i<=75; ++i){
for (auto &k:a[i]) ++pfsum[k.first][k.second];
prefix_sum();
for (int j=i; j<=75; ++j) if (j-i<=d){
int dd=d-(j-i);
memset(pfsum, 0, sizeof pfsum);
int cur=0;
for (auto &k:a[j]){
cur+=get(k.first-dd, k.second-dd, k.first+dd, k.second+dd);
}
if (i==j) cur-=a[i].size(), cur/=2;
ans+=cur;
}
}
cout << ans << '\n';
}
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> b >> n >> d >> m;
if (b==1){
sub1::solve();
}
if (b==2){
sub2::solve();
}
if (b==3){
sub3::solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
4956 KB |
Output is correct |
2 |
Correct |
10 ms |
5176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
5164 KB |
Output is correct |
2 |
Correct |
14 ms |
4956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
4952 KB |
Output is correct |
2 |
Correct |
14 ms |
4956 KB |
Output is correct |
3 |
Correct |
15 ms |
5176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
3 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
4808 KB |
Output is correct |
2 |
Correct |
46 ms |
10320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
69 ms |
4980 KB |
Output is correct |
2 |
Correct |
85 ms |
7760 KB |
Output is correct |
3 |
Correct |
77 ms |
7500 KB |
Output is correct |
4 |
Correct |
76 ms |
6868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
76 ms |
5200 KB |
Output is correct |
2 |
Correct |
93 ms |
7956 KB |
Output is correct |
3 |
Correct |
73 ms |
9092 KB |
Output is correct |
4 |
Correct |
62 ms |
7252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
10 ms |
4956 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
24 ms |
6528 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
30 ms |
6492 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
39 ms |
7000 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |