# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
725323 |
2023-04-17T09:03:22 Z |
Baytoro |
Pairs (IOI07_pairs) |
C++17 |
|
343 ms |
61936 KB |
#include <bits/stdc++.h>
using namespace std;
#define ios ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fr first
#define sc second
#define endl '\n'
#define ll long long
#define int long long
void fopn(string name){
freopen((name+".in").c_str(),"r",stdin);
freopen((name+".out").c_str(),"w",stdout);
}
const ll INF=1e18,mod=1e9+9,N=1e5+5;
template<class T, int... Ns> struct BIT {
T val = 0;
void upd(T v) { val += v; }
T query() { return val; }
};
template<class T, int N, int... Ns> struct BIT<T, N, Ns...> {
BIT<T, Ns...> bit[N+1];
template<typename... Args> void upd(int pos, Args... args) {
for (; pos <= N; pos += pos&-pos) bit[pos].upd(args...);
}
template<typename... Args> T sum(int pos, Args... args) {
T res = 0; for (; pos > 0; pos -= pos&-pos) res += bit[pos].query(args...);
return res;
}
template<typename... Args> T query(int l, int r, Args... args) {
return sum(r, args...) - sum(l-1, args...);
}
};
struct triple{
int x,y,z;
};
BIT<int,301,301,301> Bit;
void solve(){
int b,n,d,m;
cin>>b>>n>>d>>m;
if(b==1){
vector<int> a(n);
for(int i=0;i<n;i++) cin>>a[i];
sort(all(a));
int ans=0;
for(int i=0;i<n;i++){
int j=upper_bound(all(a),a[i]+d)-a.begin();
ans+=j-i-1;
}
cout<<ans<<endl;
}
else if(b==2){
vector<pair<int,int>> a(n);
for(int i=0;i<n;i++){
int x,y;cin>>x>>y;
a[i]={x+y,x-y};
}
sort(all(a));
int ans=0;
BIT<int,150005> bit;
int l=0,r=-1;
for(int i=0;i<n;i++){
while(r+1<n && a[r+1].fr-a[i].fr<=d)
bit.upd(a[++r].sc+m+1,1);
while(l<n && a[i].fr-a[l].fr>d)
bit.upd(a[l++].sc+m+1,-1);
ans+=bit.query(max(1ll,a[i].sc+m+1-d),min(2*m+1,a[i].sc+m+1+d))-1;
}
cout<<ans/2<<endl;
}
else{
vector<array<int,4>> a(n);
for(int i=0;i<n;i++){
int x,y,z;
cin>>x>>y>>z;
a[i]={x+y+z,x+y-z,x-y+z,x-y-z};
}
sort(all(a));
int l=0,r=-1;
int ans=0;
for(int i=0;i<n;i++){
while(r+1<n && a[r+1][0]-a[i][0]<=d){
r++;Bit.upd(a[r][1]+2*m+1,a[r][2]+2*m+1,a[r][3]+2*m+1,1);
}
while(l<n && a[i][0]-a[l][0]>d){
Bit.upd(a[l][1]+2*m+1,a[l][2]+2*m+1,a[l][3]+2*m+1,-1);l++;
}
ans+=Bit.query(max(1ll,a[i][1]+2*m+1-d),min(4*m+1,a[i][1]+2*m+1+d),
max(1ll,a[i][2]+2*m+1-d),min(4*m+1,a[i][2]+2*m+1+d),
max(1ll,a[i][3]+2*m+1-d),min(4*m+1,a[i][3]+2*m+1+d))-1;
}
cout<<ans/2;
}
}
main(){
//fopn("team");
ios;
int T=1;
//cin>>T;
for(int i=1;i<=T;i++){
//cout<<"Case #"<<i<<": ";
solve();
}
}
Compilation message
pairs.cpp:98:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
98 | main(){
| ^~~~
pairs.cpp: In function 'void fopn(std::string)':
pairs.cpp:13:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
13 | freopen((name+".in").c_str(),"r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pairs.cpp:14:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | freopen((name+".out").c_str(),"w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1492 KB |
Output is correct |
2 |
Correct |
1 ms |
1620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
2516 KB |
Output is correct |
2 |
Correct |
17 ms |
2516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
2552 KB |
Output is correct |
2 |
Correct |
20 ms |
2516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
2536 KB |
Output is correct |
2 |
Correct |
20 ms |
2516 KB |
Output is correct |
3 |
Correct |
24 ms |
2516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1492 KB |
Output is correct |
2 |
Correct |
2 ms |
1492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
3156 KB |
Output is correct |
2 |
Correct |
24 ms |
3144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
3144 KB |
Output is correct |
2 |
Correct |
43 ms |
3340 KB |
Output is correct |
3 |
Correct |
29 ms |
3156 KB |
Output is correct |
4 |
Correct |
29 ms |
3132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
3296 KB |
Output is correct |
2 |
Correct |
33 ms |
3176 KB |
Output is correct |
3 |
Correct |
34 ms |
3124 KB |
Output is correct |
4 |
Correct |
30 ms |
3284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
22740 KB |
Output is correct |
2 |
Correct |
11 ms |
22880 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
113 ms |
6944 KB |
Output is correct |
2 |
Correct |
86 ms |
7412 KB |
Output is correct |
3 |
Correct |
59 ms |
7372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
241 ms |
43316 KB |
Output is correct |
2 |
Correct |
239 ms |
44040 KB |
Output is correct |
3 |
Correct |
102 ms |
43920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
343 ms |
61100 KB |
Output is correct |
2 |
Correct |
294 ms |
61936 KB |
Output is correct |
3 |
Correct |
169 ms |
61920 KB |
Output is correct |