Submission #428922

# Submission time Handle Problem Language Result Execution time Memory
428922 2021-06-15T15:29:37 Z arayi Fish (IOI08_fish) C++17
100 / 100
1103 ms 31436 KB
//Arayi
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <math.h>   
#include <vector>
#include <cstring>
#include <ctime>
#include <set>
#include <bitset>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <ctime>
#include <climits>
#include <cassert>
#include <chrono>
#include <random>
#include <complex>

#define fr first
#define sc second
#define MP make_pair
#define ad push_back
#define PB push_back
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define lli long long int
#define y1 arayikhalatyan
#define j1 jigglypuff
#define ld long double
#define itn int
#define pir pair<int, int>
#define all(x) (x).begin(), (x).end()
#define str string
#define enl endl
#define en endl
#define cd complex<long double>
#define vcd vector<cd>
#define vii vector<int>
#define vlli vector<lli>
using namespace std;

lli gcd(lli a, lli b) { return (b == 0LL ? a : gcd(b, a % b)); }
ld dist(ld x, ld y1, ld x2, ld y2)
{
    return sqrt((x - x2) * (x - x2) + (y1 - y2) * (y1 - y2));
}
lli S(lli a)
{
    return (a * (a + 1LL)) / 2;
}
mt19937 rnd(363542);
char vow[] = { 'a', 'e', 'i', 'o', 'u' };
int dx[] = { 0, -1, 0, 1, -1, -1, 1, 1, 0 };
int dy[] = { -1, 0, 1, 0, -1, 1, -1, 1, 0 };


const int N = 1e6 + 30;
lli mod = 1e9 + 7;
const ld pi = acos(-1);
const int T = 200;

lli bp(lli a, lli b = mod - 2LL)
{
    lli ret = 1;
    while (b)
    {
        if (b & 1) ret *= a, ret %= mod;
        a *= a;
        a %= mod;
        b >>= 1;
    }
    return ret;
}
ostream& operator<<(ostream& c, pir a)
{
    c << a.fr << " " << a.sc;
    return c;
}
template<class T>
void maxi(T& a, T b)
{
    a = max(a, b);
}
template <class T>
void mini(T& a, T b)
{
    a = min(a, b);
}



int n, k;
pair<int, int> a[N];
lli qan[N], ans, sm[N], sw[N];
lli t1[4*N];
void upd1(int q, lli v, int l = 1, int r = k, int nd = 1)
{
    if(q > r || q < l) return;
    if(l == r)
    {
        t1[nd] = v;
        return;
    }
    int mid = (l + r) / 2;
    upd1(q, v, l, mid, nd*2);
    upd1(q, v, mid + 1, r, nd * 2 + 1);
    t1[nd] = (t1[nd*2] * t1[nd*2+1]) % mod;
}
lli qry(int l, int r, int nl = 1, int nr = k, int nd = 1)
{
    if(l > nr || r < nl) return 1;
    if(l == nl && r == nr) return t1[nd];
    int mid = (nl + nr) / 2;
    return (qry(l, min(mid, r), nl, mid, nd * 2) * qry(max(mid + 1, l), r, mid + 1, nr, nd * 2 + 1)) % mod;
}
int main()
{
    fastio;
//    freopen("input.in", "r", stdin);
    cin >> n >> k >> mod;
    for (int i = 0; i < n; i++) cin >> a[i].fr >> a[i].sc;
    sort(a,a+n);
    int i1 = k;
    for (int i = n - 1; i >= 0; i--)
    {
        if(sw[a[i].sc]) continue;
        sw[a[i].sc] = i1--;
    }
    i1 = -1;
    for (int i = 0; i < n; i++) 
    {
        a[i].sc = sw[a[i].sc];
        if(a[i].fr*2 <= a[n-1].fr) qan[a[i].sc]++, i1 = i;
    }
    for (int i = 1; i <= k; i++) upd1(i, qan[i] + 1);
    for (int i = 1; i <= k; i++) sm[i] = k + 1;
    int e = k + 1;
    for (int i = n - 1; i >= 0; i--)
    {
        while(i1 >= 0 && a[i1].fr*2 > a[i].fr)
        {
            qan[a[i1].sc]--;
            upd1(a[i1].sc, qan[a[i1].sc] + 1);
            sm[a[i1].sc] = e;
            i1--;
        }
        if(a[i].sc >= e) continue;
        e = a[i].sc;
        ans += (qry(1, e - 1) * qry(e + 1, sm[e] - 1)) % mod, ans %= mod;
        ans += qry(1, e), ans %= mod;
        ans -= qry(1, e - 1), ans %= mod, ans = (ans + mod) % mod;
    }
    cout << ans << endl;
    return 0;
}

/*
    __
  *(><)*
    \/ /
    ||/
  --||
    ||
    /\
   /  \
  /    \

*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 195 ms 5432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 86 ms 3128 KB Output is correct
2 Correct 124 ms 5456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 460 KB Output is correct
2 Correct 4 ms 468 KB Output is correct
3 Correct 4 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 137 ms 3944 KB Output is correct
2 Correct 248 ms 11168 KB Output is correct
3 Correct 221 ms 11076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 230 ms 5488 KB Output is correct
2 Correct 242 ms 5096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 140 ms 3900 KB Output is correct
2 Correct 280 ms 11508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 230 ms 5516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 260 ms 6380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 234 ms 6852 KB Output is correct
2 Correct 295 ms 8956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 515 ms 12672 KB Output is correct
2 Correct 432 ms 14976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 474 ms 12644 KB Output is correct
2 Correct 462 ms 16428 KB Output is correct
3 Correct 577 ms 19524 KB Output is correct
4 Correct 446 ms 16444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 718 ms 14236 KB Output is correct
2 Correct 1103 ms 31436 KB Output is correct
3 Correct 898 ms 28508 KB Output is correct
4 Correct 1058 ms 29944 KB Output is correct