Submission #118808

#TimeUsernameProblemLanguageResultExecution timeMemory
118808eriksuenderhaufFish (IOI08_fish)C++11
100 / 100
1975 ms65536 KiB
//#pragma GCC optimize("O3") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/rope> #define mem(a,v) memset((a), (v), sizeof (a)) #define enl printf("\n") #define case(t) printf("Case #%d: ", (t)) #define ni(n) scanf("%d", &(n)) #define nl(n) scanf("%lld", &(n)) #define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i]) #define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i]) #define pri(n) printf("%d\n", (n)) #define prl(n) printf("%lld\n", (n)) #define pii pair<int, int> #define pil pair<int, long long> #define pll pair<long long, long long> #define vii vector<pii> #define vil vector<pil> #define vll vector<pll> #define vi vector<int> #define vl vector<long long> #define pb push_back #define mp make_pair #define fi first #define se second using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef cc_hash_table<int,int,hash<int>> ht; typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset; const double pi = acos(-1); int MOD = 1e9 + 7; const int INF = 1e9 + 7; const int MAXN = 1e6 + 5; const double eps = 1e-9; pii a[MAXN]; vi arr[MAXN]; priority_queue<pii> pq; int ind[MAXN], rev[MAXN], cnt[MAXN]; ll seg[MAXN*4]; void build(int l, int r, int k) { if (l == r) { seg[k] = 1; return; } int m = (l+r) / 2; build(l, m, k*2); build(m+1, r, k*2+1); seg[k] = (seg[k*2] * seg[k*2+1]) % MOD; } void upd(int l, int r, int k, int a, int v) { if (a <= l && r <= a) { seg[k] = v; return; } int m = (l+r) / 2; if (a <= m) upd(l, m, k*2, a, v); else upd(m+1, r, k*2+1, a, v); seg[k] = (seg[k*2] * seg[k*2+1]) % MOD; } ll qry(int l, int r, int k, int a, int b) { if (r < a || b < l || a > b) return 1; if (a <= l && r <= b) return seg[k]; int m = (l+r) / 2; return (qry(l,m,k*2,a,b)*qry(m+1,r,k*2+1,a,b)) % MOD; } int main() { int n, k; scanf("%d %d %d", &n, &k, &MOD); a[0] = mp(0, 0); vii tmp; for (int i = 1; i <= n; i++) { scanf("%d %d", &a[i].fi, &a[i].se); arr[a[i].se].pb(a[i].fi); pq.push(a[i]); } for (int i = 1; i <= k; i++) { ind[i] = i; sort(arr[i].begin(), arr[i].end()); } build(1, k, 1); sort(ind + 1, ind + k+1, [](int l, int r) { return arr[l].back() > arr[r].back(); }); for (int i = 1; i <= k; i++) rev[ind[i]] = i; ll ans = 0; for (int i = 1; i <= k; i++) { cnt[ind[i]] = (int)arr[ind[i]].size(); upd(1, k, 1, i, cnt[ind[i]] % MOD + 1); } for (int i = 1; i <= k; i++) { int sz = arr[ind[i]].back() / 2; while (!pq.empty()) { if (pq.top().fi <= sz) break; pii cur = pq.top(); pq.pop(); cnt[cur.se]--; upd(1, k, 1, rev[cur.se], cnt[cur.se] % MOD + 1); } ll v1 = cnt[ind[i]], v2 = qry(1, k, 1, i + 1, k); int lo = 1, hi = i; while (lo < hi) { int mi = (lo+hi) / 2; if (upper_bound(arr[ind[i]].begin(), arr[ind[i]].end(), arr[ind[mi]].back() / 2) - arr[ind[i]].begin() == v1) hi = mi; else lo = mi + 1; } ll v3 = qry(1, k, 1, lo, i - 1); v1 %= MOD; ans = (ans + (v1 * v2) % MOD + (v2 * v3) % MOD) % MOD; } printf("%lld\n", ans); return 0; }

Compilation message (stderr)

fish.cpp: In function 'int main()':
fish.cpp:76:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d", &n, &k, &MOD);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
fish.cpp:80:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &a[i].fi, &a[i].se);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...