Submission #53867

#TimeUsernameProblemLanguageResultExecution timeMemory
53867baactreeFish (IOI08_fish)C++17
100 / 100
1472 ms42628 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll tree[1 << 20]; int sz = 1 << 19; int n, m, mod; pair<int, int> arr[500005]; vector<int> vec[500005]; bool chk[500005]; int t[500005]; void update(int idx, int val) { idx += sz; tree[idx] += val; idx /= 2; while (idx) { tree[idx] = tree[idx * 2] * tree[idx * 2 + 1] % mod; idx /= 2; } } ll query(int le, int ri) { le += sz; ri += sz; ll ret = 1; while (le <= ri) { if (le & 1)ret = ret * tree[le++] % mod; if (!(ri & 1))ret = ret * tree[ri--] % mod; le /= 2; ri /= 2; } return ret; } int main() { scanf("%d%d%d", &n, &m, &mod); for (int i = 0; i < n; i++) scanf("%d%d", &arr[i].first, &arr[i].second); sort(arr, arr + n); int cnt = 0; for (int i = n - 1; i >= 0; i--) { if (!chk[arr[i].second]) { t[arr[i].second] = ++cnt; chk[arr[i].second] = true; } } for (int i = 0; i < n; i++) { arr[i].second = t[arr[i].second]; vec[arr[i].second].push_back(i); } ll ans = 0; for (int i = 0; i < 500005; i++) tree[i + sz] = 1; for (int i = sz - 1; i; i--) tree[i] = tree[i * 2] * tree[i * 2 + 1] % mod; int idx = 0; for (int i = 0; i < n; i++) { while (arr[idx].first * 2 <= arr[i].first) { update(arr[idx].second, 1); idx++; } if (vec[arr[i].second].back()==i) { update(arr[i].second, -1); ans = (ans + query(arr[i].second, 500004)) % mod; int it = -1; for (auto x : vec[arr[i].second]) { if (arr[x].first > arr[i].first / 2) { it = x; break; } } int le = arr[it].first * 2; int l, r, mid, ri; l = 1; r = arr[i].second; while (l <= r) { mid = (l + r) / 2; if (arr[vec[mid].back()].first < le) { ri = mid; r = mid - 1; } else l = mid + 1; } ans = (ans + query(ri, arr[i].second - 1) * query(arr[i].second + 1, 500004)) % mod; update(arr[i].second, 1); } } printf("%lld\n", ans); return 0; }

Compilation message (stderr)

fish.cpp: In function 'int main()':
fish.cpp:33:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d", &n, &m, &mod);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
fish.cpp:35:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &arr[i].first, &arr[i].second);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fish.cpp:81:22: warning: 'ri' may be used uninitialized in this function [-Wmaybe-uninitialized]
    ans = (ans + query(ri, arr[i].second - 1) * query(arr[i].second + 1, 500004)) % mod;
                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#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...
#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...