Submission #762754

#TimeUsernameProblemLanguageResultExecution timeMemory
762754caganyanmazPairs (IOI07_pairs)C++17
18 / 100
198 ms46252 KiB
#include <bits/stdc++.h> #define int int64_t #define pb push_back using namespace std; struct SegTree { int n; vector<int> data, left, right; SegTree(int n) : n(n), data(1, 0), left(1, -1), right(1, -1) {} void cc(int index) { if (left[index] == -1) { left[index] = data.size(); data.pb(0); left.pb(-1); right.pb(-1); } if (right[index] == -1) { right[index] = data.size(); data.pb(0); left.pb(-1); right.pb(-1); } } void update(int l, int r, int index, int i, int val) { if (i >= r || l > i) return; if (l + 1 == r) { data[index] += val; return; } cc(index); int m = l+r>>1; update(l, m, left[index], i, val); update(m, r, right[index], i, val); data[index] = data[left[index]] + data[right[index]]; } int get(int l, int r, int index, int ss, int ee) { if (ss >= r || l >= ee) return 0; if (ee >= r && l >= ss) return data[index]; int m = l+r>>1; int lres = 0, rres = 0; if (left[index] != -1) lres = get(l, m, left[index], ss, ee); if (right[index] != -1) rres = get(m, r, right[index], ss, ee); return lres + rres; } void update(int i, int val) { update(0, n, 0, i, val ); } int get(int ss, int ee) { return get(0, n, 0, ss, ee); } }; void solve1d() { int n, d, m; cin >> n >> d >> m; SegTree st(m); vector<int> v(n); for (int& i : v) { cin >> i; st.update(i, 1); } int encounters = 0; for (int i : v) encounters += st.get(i-d, i+d+1) - 1; //assert(encounters % 2 == 0); cout << (encounters / 2) << "\n"; } int32_t main() { int b; cin >> b; assert(b == 1); solve1d(); }

Compilation message (stderr)

pairs.cpp: In member function 'void SegTree::update(int64_t, int64_t, int64_t, int64_t, int64_t)':
pairs.cpp:39:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   39 |                 int m = l+r>>1;
      |                         ~^~
pairs.cpp: In member function 'int64_t SegTree::get(int64_t, int64_t, int64_t, int64_t, int64_t)':
pairs.cpp:50:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   50 |                 int m = l+r>>1;
      |                         ~^~
#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...