Submission #256490

#TimeUsernameProblemLanguageResultExecution timeMemory
256490mode149256Fish (IOI08_fish)C++14
0 / 100
465 ms65536 KiB
/*input 5 3 7 8 3 5 3 4 3 2 3 2 3 */ #include <bits/stdc++.h> using namespace std; namespace my_template { typedef long long ll; typedef long double ld; typedef complex<ld> cd; typedef pair<int, int> pi; typedef pair<ll, ll> pl; typedef pair<ld, ld> pd; typedef vector<int> vi; typedef vector<vi> vii; typedef vector<ld> vd; typedef vector<ll> vl; typedef vector<vl> vll; typedef vector<pi> vpi; typedef vector<vpi> vpii; typedef vector<pl> vpl; typedef vector<cd> vcd; typedef vector<pd> vpd; typedef vector<bool> vb; typedef vector<vb> vbb; typedef std::string str; typedef std::vector<str> vs; #define x first #define y second #define debug(...) cout<<"["<<#__VA_ARGS__<<": "<<__VA_ARGS__<<"]\n" const ld PI = 3.14159265358979323846264338327950288419716939937510582097494L; template<typename T> pair<T, T> operator+(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x + b.x, a.y + b.y); } template<typename T> pair<T, T> operator-(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x - b.x, a.y - b.y); } template<typename T> T operator*(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.x + a.y * b.y); } template<typename T> T operator^(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.y - a.y * b.x); } template<typename T> void print(vector<T> vec, string name = "") { cout << name; for (auto u : vec) cout << u << ' '; cout << '\n'; } } using namespace my_template; ll MOD = 1000000007; const ll INF = std::numeric_limits<ll>::max(); const int MX = 500101; ll mypow(ll a, ll b) { ll ret = 1; while (b) { if (b & 1) ret = (ret * a) % MOD; a = (a * a) % MOD; b >>= 1; } return ret; } int N, K; struct node { int l, r; ll lazy; node *left = nullptr; node *right = nullptr; node(int a, int b): l(a), r(b) { lazy = 1; if (l != r) { left = new node(l, (l + r) / 2); right = new node((l + r) / 2 + 1, r); } } void prod(int a, int b, ll kart) { if (r < a or b < l) return; else if (a <= l and r <= b) { lazy = (lazy * kart) % MOD; } else { left->prod(a, b, kart); right->prod(a, b, kart); } } ll get(int pos) { if (l == r) return lazy; else if (pos <= (l + r) / 2) return (left->get(pos) * lazy) % MOD; else return (right->get(pos) * lazy) % MOD; } }; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> N >> K >> MOD; vpl sk(N); for (int i = 0; i < N; ++i) { cin >> sk[i].x >> sk[i].y; sk[i].y--; } sort(sk.rbegin(), sk.rend()); ll ats = 0; node med(0, N - 1); int j = -1; vi last(K, -1); vi kiek(K, 0); vi prad(K, 0); for (int i = 0; i < N; ++i) { int k = (int)sk[i].y; if (!kiek[k]) prad[k] = i; kiek[k]++; } for (int i = 0; i < N; ++i) { int k = (int)sk[i].y; // if (buvo[sk[i].y]) continue; while (sk[j + 1].x >= 2 * sk[i].x) j++; // if (last[k] == -1) ats += med.get(i); // buvo[k] = true; if (last[k] + 1 <= min(prad[k], j)) { // printf("nuo %d %d kart %d\n", last[k] + 1, min(prad[k], j), kiek[k] + 1); med.prod(last[k] + 1, min(prad[k], j), kiek[k] + 1); } kiek[k]--; last[k] = max(last[k], min(prad[k], j)); } last = vi(K, -1); for (int i = 0; i < N; ++i) { if (last[sk[i].y] == -1) { last[sk[i].y] = 1; ll val = med.get(i); // printf("i = %d, sk = %lld %lld, val = %lld\n", i, sk[i].x, sk[i].y, val); ats = (ats + val) % MOD; } } printf("%lld\n", ats); } /* Look for: * special cases (n=1?) * overflow (ll vs int?) * the exact constraints (multiple sets are too slow for n=10^6 :( ) * array bounds */
#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...