Submission #65428

#TimeUsernameProblemLanguageResultExecution timeMemory
65428KieranHorganPairs (IOI07_pairs)C++17
37 / 100
221 ms84500 KiB
#include <bits/stdc++.h> using namespace std; #define endl '\n' #define ll long long #define int long long #define ld double #define pii pair<int,int> #define rand() abs((rand()<<15)|rand()) #define randll() abs(((long long)rand()<<30) int B, N, D, M; int n; vector<vector<int>> rows; struct SegmentTree { vector<vector<int>> st; SegmentTree(int N_) { n = N_; st.assign(4*n, vector<int>(0)); build(); } void build(int id=1, int l=0, int r=n) { if(l+1 == r) { st[id] = rows[l]; return; } int mid = (l+r)/2; build(id*2 , l, mid); build(id*2+1, mid, r); merge(st[id*2].begin(), st[id*2].end(), st[id*2+1].begin(), st[id*2+1].end(), back_inserter(st[id])); } int query(int r1, int c1, int r2, int c2, int id=1, int l=0, int r=n) { if(l >= r1 && r <= r2) { for(auto x: st[id]) return upper_bound(st[id].begin(), st[id].end(), c2)-lower_bound(st[id].begin(), st[id].end(), c1); } if(l >= r2 || r <= r1) return 0; int mid = (l+r)/2; return query(r1, c1, r2, c2, id*2 , l, mid) + query(r1, c1, r2, c2, id*2+1, mid, r); } }; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> B >> N >> D >> M; if(B == 1) { vector<int> a(N); for(auto &x: a) cin >> x; sort(a.begin(), a.end()); int ans = 0; for(auto x: a) ans += upper_bound(a.begin(), a.end(), x+D)-lower_bound(a.begin(), a.end(), x-D)-1; cout << ans/2 << endl; } if(B == 2) { vector<pair<int, int>> a(N); rows.assign(2*M-1, vector<int>(0)); for(int i = 0; i < N; i++) { int x, y; cin >> x >> y; x--; y--; rows[x+y].push_back(M-1-(x-y)); a[i] = {x+y, M-1-(x-y)}; } for(auto &v: rows) sort(v.begin(), v.end()); SegmentTree st(2*M-1); int ans = 0; for(auto p: a) { ans += st.query(p.first-D, p.second-D, p.first+D+1, p.second+D)-1; int cur = 0; for(auto q: a) if(q != p && max(abs(p.first-q.first), abs(p.second-q.second)) <= D) { cur++; } } if(ans%2) return -1; cout << (ans)/2 << endl; } }

Compilation message (stderr)

pairs.cpp: In member function 'long long int SegmentTree::query(long long int, long long int, long long int, long long int, long long int, long long int, long long int)':
pairs.cpp:37:16: warning: unused variable 'x' [-Wunused-variable]
       for(auto x: st[id])
                ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...