Submission #428372

# Submission time Handle Problem Language Result Execution time Memory
428372 2021-06-15T11:05:35 Z arayi Fish (IOI08_fish) C++17
0 / 100
368 ms 13056 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, lli> a[N];
lli qan[N], sm = 1, s = 1, col[N], cl[N], ans;
int main()
{
    fastio;
    cin >> n >> k >> mod;
    for (int i = 0; i < n; i++)
        cin >> a[i].fr >> a[i].sc;
    sort(a,a+n);
    int i1 = -1;
    for (int i = 0; i < n; i++)
        if(a[i].fr*2 <= a[n-1].fr) qan[a[i].sc]++, i1 = i;
    for (int i = 1; i <= k; i++) sm *= (qan[i] + 1LL), sm%=mod, col[i] = qan[i];
    for (int i = n - 1; i >= 0; i--)
    {
        if(i == n - 1)
        {
            ans += sm;
            col[a[i].sc]++;
            cl[a[i].sc] = 1;
            s*=(qan[a[i].sc] + 1LL), s%=mod;
            continue;
        }
        while(i1 >= 0 && a[i1].fr*2> a[i].fr)
        {
            sm*=bp(qan[a[i1].sc] + 1), sm%=mod;
            if(cl[a[i1].sc]) s*=bp(qan[a[i1].sc] + 1LL), s%=mod;
            qan[a[i1].sc]--;
            sm *= (qan[a[i1].sc] + 1), sm%=mod;
            if(cl[a[i1].sc]) s *= (qan[a[i1].sc] + 1LL), s%=mod;
            i1--;
        }
        if(cl[a[i].sc]) continue;
        if(col[a[i].sc] == qan[a[i].sc]) 
        {
            ans += (sm*bp(qan[a[i].sc] + 1LL)), ans %= mod, col[a[i].sc]++;
            ans -= ((sm*bp(qan[a[i].sc]))%mod)*bp(s), ans%=mod, ans=(ans + mod)%mod;
        }
        ans += sm*bp(s), ans %= mod;
        s *= (qan[a[i].sc] + 1LL), s %= mod;
        cl[a[i].sc] = 1;
    }
    cout << ans << endl;
    return 0;
}

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

*/
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 328 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 332 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Incorrect 253 ms 8304 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 460 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 98 ms 3772 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 332 KB Output is correct
2 Incorrect 4 ms 460 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 177 ms 5272 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 314 ms 8416 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 120 ms 5220 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 239 ms 7748 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 283 ms 8724 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 225 ms 7916 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 312 ms 11088 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 319 ms 11048 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 368 ms 13056 KB Output isn't correct
2 Halted 0 ms 0 KB -