Submission #445613

#TimeUsernameProblemLanguageResultExecution timeMemory
445613JerryLiu06Fish (IOI08_fish)C++17
100 / 100
995 ms30084 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using db = double; using str = string; using pi = pair<int, int>; using pl = pair<ll, ll>; using pd = pair<db, db>; using vi = vector<int>; using vb = vector<bool>; using vl = vector<ll>; using vd = vector<db>; using vs = vector<str>; using vpi = vector<pi>; using vpl = vector<pl>; using vpd = vector<pd>; #define mp make_pair #define f first #define s second #define sz(x) (int)(x).size() #define bg(x) begin(x) #define all(x) bg(x), end(x) #define sor(x) sort(all(x)) #define rsz resize #define ins insert #define ft front() #define bk back() #define pb push_back #define pf push_front #define lb lower_bound #define ub upper_bound #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define F0R(i, a) FOR(i, 0, a) #define ROF(i, a, b) for (int i = (b) - 1; i >= (a); i--) #define R0F(i, a) ROF(i, 0, a) #define EACH(a, x) for (auto& a : x) ll cdiv(ll a, ll b) { return a / b + ((a ^ b) > 0 && a % b); } ll fdiv(ll a, ll b) { return a / b - ((a ^ b) < 0 && a % b); } template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } template<class T> void remDup(vector<T>& v) { sor(v); v.erase(unique(all(v)), v.end()); } const int MX = 5e5 + 10; const ll INF = 1e18; int MOD = 1e9 + 7; struct mint { int v; explicit operator int() const { return v; } mint() { v = 0; } mint(ll _v) { v = int((-MOD < _v && _v < MOD) ? _v : _v % MOD); if (v < 0) v += MOD; } friend bool operator==(const mint& a, const mint& b) { return a.v == b.v; } friend bool operator!=(const mint& a, const mint& b) { return !(a == b); } friend bool operator<(const mint& a, const mint& b) { return a.v < b.v; } mint& operator+=(const mint& m) { if ((v += m.v) >= MOD) v -= MOD; return *this; } mint& operator-=(const mint& m) { if ((v -= m.v) < 0) v += MOD; return *this; } mint& operator*=(const mint& m) { v = int((ll) v * m.v % MOD); return *this; } mint& operator/=(const mint& m) { return (*this) *= inv(m); } friend mint pow(mint a, long long p) { mint ans = 1; for ( ; p; p /= 2, a *= a) if (p & 1) ans *= a; return ans; } friend mint inv(const mint& a) { return pow(a, MOD - 2); } mint operator-() const { return mint(-v); } mint& operator++() { return *this += 1; } mint& operator--() { return *this -= 1; } friend mint operator+(mint a, const mint& b) { return a += b; } friend mint operator-(mint a, const mint& b) { return a -= b; } friend mint operator*(mint a, const mint& b) { return a *= b; } friend mint operator/(mint a, const mint& b) { return a /= b; } }; int F, K; vpi fish; vector<array<int, 3>> A; int ord[MX], nxt[MX]; mint tree[4 * MX], ans = 0; void update(int x, int l, int r, int pos, mint val) { int mid = (l + r) / 2; if (l > pos || r < pos) return ; if (l == r) { tree[x] += val; return ; } update(2 * x, l, mid, pos, val); update(2 * x + 1, mid + 1, r, pos, val); tree[x] = tree[2 * x] * tree[2 * x + 1]; } mint query(int x, int l, int r, int tl, int tr) { int mid = (l + r) / 2; if (l > tr || r < tl) return 1; if (tl <= l && r <= tr) return tree[x]; return query(2 * x, l, mid, tl, tr) * query(2 * x + 1, mid + 1, r, tl, tr); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> F >> K >> MOD; A.rsz(K + 1); fish.rsz(F); F0R(i, F) { int L, T; cin >> L >> T; fish[i] = {L, T}; ckmax(A[T][0], L); A[T][1]++; A[T][2] = T; } sor(fish); sor(A); FOR(i, 1, K + 1) { update(1, 1, K, i, A[i][1] + 1); ord[A[i][2]] = i; } int ptr = F - 1; FOR(i, 1, K + 1) nxt[i] = i; ROF(i, 1, K + 1) { while (ptr >= 0 && fish[ptr].f > A[i][0] / 2) { int ind = ord[fish[ptr].s]; update(1, 1, K, ind, -1); nxt[ind] = i; ptr--; } mint cur = query(1, 1, K, 1, i - 1); ans += cur * (query(1, 1, K, i + 1, nxt[i]) - 1); ans += cur * query(1, 1, K, i, i); } cout << int(ans); }

Compilation message (stderr)

fish.cpp: In function 'void update(int, int, int, int, mint)':
fish.cpp:92:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   92 |     if (l > pos || r < pos) return ; if (l == r) { tree[x] += val; return ; }
      |     ^~
fish.cpp:92:38: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   92 |     if (l > pos || r < pos) return ; if (l == r) { tree[x] += val; return ; }
      |                                      ^~
fish.cpp: In function 'mint query(int, int, int, int, int)':
fish.cpp:97:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   97 |     if (l > tr || r < tl) return 1; if (tl <= l && r <= tr) return tree[x];
      |     ^~
fish.cpp:97:37: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   97 |     if (l > tr || r < tl) return 1; if (tl <= l && r <= tr) return tree[x];
      |                                     ^~
#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...