제출 #363476

#제출 시각아이디문제언어결과실행 시간메모리
363476hivakaramiFish (IOI08_fish)C++14
0 / 100
374 ms65540 KiB
#include<bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; #define f first #define s second const int N = 5e5 + 10; const int sq = 100; const ll mod = 1e9 + 7; const int inf = 1e9; ll seg[4*N], m, cnt[N]; int n, k, f[N]; bool last[N]; vector<ll> ind[N], v; vector<pair<ll, int>> all; ll get(int l, int r, int b = 0, int e = k, int id = 1) { if(r <= b || e <= l) return 1; if(l <= b && r <= e) return seg[id]; int mid = (b + e) / 2; return (get(l, r, b, mid, id*2) * get(l, r, mid, e, id*2+1))%m; } void upd(int x, ll val, int b = 0, int e = k, int id = 1) { if(b + 1 == e) { seg[id] = val%m; return; } int mid = (b + e) / 2; if(x < mid) upd(x, val, b, mid, id*2); else upd(x, val, mid, e, id*2+1); seg[id] = (seg[id*2] * seg[id*2+1]) % m; } inline void add(int r) { cnt[f[r]]++; upd(f[r], cnt[f[r]]); } inline int find(ll p, int r) { p = all[p].f; int l = 0; while(l + 1 < r) { int mid = (l + r) / 2; ll len = v[mid]; if(len >= 2ll*p) l = mid; else r = mid; } return l+1; } int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> n >> k >> m; //m = mod; for(int i = 0; i < n; i++) { ll l, c; cin >> l >> c; all.push_back({l, c}); f[c] = -1; } sort(all.begin(), all.end()); reverse(all.begin(), all.end()); //cout << "////////" << endl; for(int i = 0; i < n; i++) { int c = all[i].s; ind[c].push_back(i); if(f[c] == -1) { f[c] = v.size(); v.push_back(all[i].f); //cout << c << ' ' << f[c] << ' ' << all[i].f << endl; add(c); last[i] = true; } //cout << all[i].f << ' ' << c << endl; } //cout << "///////" << endl; ll ans = 0; int j = n-1; for(int i = n-1; i >= 0; i--) { int c = all[i].s; while(j >= i && all[i].f >= 2ll * all[j].f) { add(all[j].s); j--; } if(!last[i]) continue; int x = upper_bound(ind[c].begin(), ind[c].end(), j) - ind[c].begin(); x--; x = ind[c][x]; x = find(x, f[c]+1); ll p1 = get(f[c]+1, k), p2 = get(x, f[c]); ll t = (cnt[f[c]] - 1); ll res = (p1 * t)%m + (p1 * p2)%m; //cout << p1 << ' ' << p2 << ' ' << t << ' ' << res << endl << endl; ans = (ans + res) % m; } cout << ans << endl; return 0; }
#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...