Submission #447954

#TimeUsernameProblemLanguageResultExecution timeMemory
447954parsabahramiFish (IOI08_fish)C++17
0 / 100
420 ms20872 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; 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) 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[_]; if (!lst[g[i]]) lst[g[i]] = _; } 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; ret = (ret + get(1, j + 1)) % mod; } printf("%d\n", ret); return 0; }

Compilation message (stderr)

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