Submission #447991

#TimeUsernameProblemLanguageResultExecution timeMemory
447991parsabahramiFish (IOI08_fish)C++17
100 / 100
1072 ms53572 KiB
/* I do it for the glory */ #include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<int, int> pii; #define SZ(x) (int) x.size() #define F first #define S second #define lc id << 1 #define rc lc | 1 const int N = 5e5 + 10; int lst[N], seg[N << 2], ord[N], A[N], g[N], k, mod, n; vector<int> vec[N], tmp; void upd(int p, int id = 1, int l = 1, int r = n + 1) { if (r - l < 2) { seg[id] = (seg[id] + 1) % mod; return; } int md = (l + r) >> 1; p < md ? upd(p, lc, l, md) : upd(p, rc, md, r); seg[id] = 1ll * seg[lc] * seg[rc] % mod; } int get(int ql, int qr, int id = 1, int l = 1, int r = n + 1) { if (qr <= l || r <= ql || ql >= qr) return 1; if (ql <= l && r <= qr) return seg[id]; int md = (l + r) >> 1; return 1ll * get(ql, qr, lc, l, md) * get(ql, qr, rc, md, r) % mod; } int main() { scanf("%d%d%d", &n, &k, &mod); for (int i = 1; i <= n; i++) { scanf("%d%d", &A[i], &g[i]), ord[i] = i; } sort(ord + 1, ord + n + 1, [&] (int i, int j) { return A[i] < A[j]; }); for (int _ = n; _; _--) { int i = ord[_]; vec[g[i]].push_back(_); tmp.push_back(A[i]); if (!lst[g[i]]) lst[g[i]] = _; } for (int i = 1; i <= k; i++) reverse(begin(vec[i]), end(vec[i])); reverse(begin(tmp), end(tmp)); int ret = 0; fill(seg, seg + N * 4, 1); for (int j = 1, pt = 0; j <= n; j++) { int i = ord[j]; while (A[ord[pt + 1]] * 2 <= A[i]) pt++, upd(lst[g[ord[pt]]]); if (j != lst[g[i]]) continue; auto it = upper_bound(vec[g[i]].begin(), vec[g[i]].end(), pt); assert(it != vec[g[i]].end()); int x = get(j, j + 1), y = get(1, j); x = (x - 1 + mod) % mod; ret = (ret + 1ll * x * y % mod) % mod; int nxt = lower_bound(begin(tmp), end(tmp), 2 * A[ord[*it]]) - begin(tmp) + 1; ret = (ret + 1ll * get(j + 1, nxt) * get(1, j) % mod) % mod; } printf("%d\n", ret); return 0; }

Compilation message (stderr)

fish.cpp: In function 'int main()':
fish.cpp:34:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |     scanf("%d%d%d", &n, &k, &mod);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
fish.cpp:36:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |         scanf("%d%d", &A[i], &g[i]), ord[i] = i;
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
#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...