Submission #445598

# Submission time Handle Problem Language Result Execution time Memory
445598 2021-07-18T21:23:15 Z JerryLiu06 Fish (IOI08_fish) C++17
0 / 100
553 ms 20164 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; bool vis[MX]; mint tree[4 * MX], ans = 0;

void build(int x, int l, int r) {
    if (l == r) { tree[x] = 1; return ; } int mid = (l + r) / 2;

    build(2 * x, l, mid); build(2 * x + 1, mid + 1, r); tree[x] = tree[2 * x] * tree[2 * x + 1];
}
void update(int x, int l, int r, int pos, mint val, int T) { int mid = (l + r) / 2;
    if (l > pos || r < pos) return ; if (l == r) { if (!T) tree[x] += val; else tree[x] = val; return ; }

    update(2 * x, l, mid, pos, val, T); update(2 * x + 1, mid + 1, r, pos, val, T); tree[x] = tree[2 * x] * tree[2 * x + 1];
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);

    cin >> F >> K >> MOD; fish.rsz(F); F0R(i, F) cin >> fish[i].f >> fish[i].s;

    sor(fish); reverse(all(fish)); build(1, 1, K); EACH(P, fish) update(1, 1, K, P.s, 1, 0);

    int ptr = 0; EACH(P, fish) if (!vis[P.s]) {
    	
        while (ptr < sz(fish) && fish[ptr].f > P.f / 2) {
            if (!vis[fish[ptr].s]) update(1, 1, K, fish[ptr].s, -1, 0); ptr++;
        }
        vis[P.s] = true; ans += tree[1]; update(1, 1, K, P.s, 1, 1);
    }
    cout << int(ans);
}

Compilation message

fish.cpp: In function 'void update(int, int, int, int, mint, int)':
fish.cpp:97:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   97 |     if (l > pos || r < pos) return ; if (l == r) { if (!T) tree[x] += val; else tree[x] = val; return ; }
      |     ^~
fish.cpp:97:38: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   97 |     if (l > pos || r < pos) return ; if (l == r) { if (!T) tree[x] += val; else tree[x] = val; return ; }
      |                                      ^~
fish.cpp: In function 'int main()':
fish.cpp:112:13: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
  112 |             if (!vis[fish[ptr].s]) update(1, 1, K, fish[ptr].s, -1, 0); ptr++;
      |             ^~
fish.cpp:112:73: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
  112 |             if (!vis[fish[ptr].s]) update(1, 1, K, fish[ptr].s, -1, 0); ptr++;
      |                                                                         ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 8140 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 8140 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 8024 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 8144 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8156 KB Output is correct
2 Incorrect 5 ms 8140 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8140 KB Output is correct
2 Incorrect 235 ms 18180 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 8156 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 8140 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 112 ms 12136 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8140 KB Output is correct
2 Correct 8 ms 8268 KB Output is correct
3 Incorrect 7 ms 8140 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 203 ms 14452 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 249 ms 18056 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 221 ms 14812 KB Output is correct
2 Incorrect 358 ms 18956 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 319 ms 17988 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 394 ms 19444 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 341 ms 17476 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 491 ms 18828 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 398 ms 16964 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 553 ms 20164 KB Output isn't correct
2 Halted 0 ms 0 KB -