답안 #445613

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
445613 2021-07-19T04:35:49 Z JerryLiu06 Fish (IOI08_fish) C++17
100 / 100
995 ms 30084 KB
#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

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];
      |                                     ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8140 KB Output is correct
2 Correct 4 ms 8156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8140 KB Output is correct
2 Correct 184 ms 14276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 96 ms 11872 KB Output is correct
2 Correct 108 ms 13308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 8140 KB Output is correct
2 Correct 7 ms 8268 KB Output is correct
3 Correct 7 ms 8268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 132 ms 12752 KB Output is correct
2 Correct 242 ms 18860 KB Output is correct
3 Correct 227 ms 18756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 239 ms 14220 KB Output is correct
2 Correct 230 ms 19120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 158 ms 12812 KB Output is correct
2 Correct 252 ms 14388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 240 ms 14040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 286 ms 14576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 275 ms 14600 KB Output is correct
2 Correct 449 ms 21684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 546 ms 16792 KB Output is correct
2 Correct 416 ms 18128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 527 ms 16824 KB Output is correct
2 Correct 522 ms 21796 KB Output is correct
3 Correct 604 ms 22724 KB Output is correct
4 Correct 478 ms 21820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 647 ms 18372 KB Output is correct
2 Correct 995 ms 29064 KB Output is correct
3 Correct 988 ms 30084 KB Output is correct
4 Correct 952 ms 28036 KB Output is correct