# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
988412 |
2024-05-24T16:15:50 Z |
huutuan |
Pairs (IOI07_pairs) |
C++14 |
|
213 ms |
10448 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 (int j=i; j<=75; ++j) if (j-i<=d){
int dd=d-(j-i);
memset(pfsum, 0, sizeof pfsum);
for (auto &k:a[i]) ++pfsum[k.first][k.second];
prefix_sum();
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 |
2 ms |
4696 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 |
11 ms |
4952 KB |
Output is correct |
2 |
Correct |
10 ms |
4956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
5084 KB |
Output is correct |
2 |
Correct |
15 ms |
4952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
4956 KB |
Output is correct |
2 |
Correct |
17 ms |
5212 KB |
Output is correct |
3 |
Correct |
18 ms |
4956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4444 KB |
Output is correct |
2 |
Correct |
2 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
51 ms |
4888 KB |
Output is correct |
2 |
Correct |
48 ms |
10448 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
72 ms |
4952 KB |
Output is correct |
2 |
Correct |
93 ms |
8120 KB |
Output is correct |
3 |
Correct |
78 ms |
7484 KB |
Output is correct |
4 |
Correct |
83 ms |
7112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
75 ms |
4956 KB |
Output is correct |
2 |
Correct |
96 ms |
8148 KB |
Output is correct |
3 |
Correct |
74 ms |
9172 KB |
Output is correct |
4 |
Correct |
77 ms |
7400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
97 ms |
4748 KB |
Output is correct |
2 |
Correct |
168 ms |
4944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
7040 KB |
Output is correct |
2 |
Correct |
67 ms |
7304 KB |
Output is correct |
3 |
Correct |
125 ms |
7308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
72 ms |
7516 KB |
Output is correct |
2 |
Correct |
184 ms |
7504 KB |
Output is correct |
3 |
Correct |
202 ms |
7332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
148 ms |
7908 KB |
Output is correct |
2 |
Correct |
213 ms |
7928 KB |
Output is correct |
3 |
Correct |
203 ms |
7912 KB |
Output is correct |