Submission #599740

#TimeUsernameProblemLanguageResultExecution timeMemory
599740gg123_pePairs (IOI07_pairs)C++14
60 / 100
103 ms7484 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair <pair<char,char>, pair<char,char>> T; #define f(i,a,b) for(ll i = a; i < b; i++) #define fa(i,a,b) for(ll i = a; i >= b; i--) const int N = 150005, M = 75001; int b, n, d, m, bit[N]; vector <vector <int>> a; ll ans; void upd(int u, int val){ for(; u < N; u = (u|(u+1))) bit[u] += val; } int get(int u){ int res = 0; for(; u >= 0; u = (u&(u+1)) - 1) res += bit[u]; return res; } int que(int l, int r){ return get(r) - get(l-1); } int main(){ cin >> b >> n >> d >> m; a.resize(n); f(i,0,n) { a[i].resize(b); f(j,0,b) cin >> a[i][j]; } if(b == 1){ sort(a.begin(), a.end()); int l = 0; f(i,0,n){ while(a[i][0] - a[l][0] > d) l++; ans += (ll) (i - l); } cout << ans << "\n"; return 0; } if(b == 2){ f(i,0,n){ int u = a[i][0] + a[i][1], v = a[i][0] - a[i][1] + M; a[i][0] = u, a[i][1] = v; } sort(a.begin(), a.end()); int l = 0; f(i,0,n){ while(a[i][0] - a[l][0] > d){ upd(a[l][1], -1); l++; } ans += (ll) que(max(0, a[i][1] - d), min(N-1, a[i][1]+d)); upd(a[i][1], 1); } cout << ans << "\n"; return 0; } cout << ans << "\n"; return 0; }
#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...