結果

問題 No.2197 Same Dish
ユーザー lddlinanlddlinan
提出日時 2023-03-14 15:51:38
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,541 bytes
コンパイル時間 2,205 ms
コンパイル使用メモリ 87,944 KB
実行使用メモリ 6,108 KB
最終ジャッジ日時 2023-10-18 11:45:48
合計ジャッジ時間 2,490 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,328 KB
testcase_01 AC 2 ms
5,328 KB
testcase_02 AC 2 ms
5,328 KB
testcase_03 AC 2 ms
5,328 KB
testcase_04 AC 2 ms
5,328 KB
testcase_05 AC 2 ms
5,328 KB
testcase_06 AC 2 ms
5,328 KB
testcase_07 AC 2 ms
5,328 KB
testcase_08 WA -
testcase_09 AC 2 ms
5,328 KB
testcase_10 WA -
testcase_11 AC 2 ms
5,328 KB
testcase_12 WA -
testcase_13 AC 10 ms
5,456 KB
testcase_14 AC 55 ms
6,016 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 63 ms
6,108 KB
testcase_20 WA -
testcase_21 AC 33 ms
6,108 KB
testcase_22 AC 38 ms
6,108 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include <map>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <algorithm>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <string>
using namespace std;

bool rcmp(int a, int b) { return a>b; }
typedef long long LL;



typedef struct { int s, e; } RNode;
RNode rs[100004];
bool mycmp(const RNode& a, const RNode& b) { return a.s<b.s; }
#define MOD 998244353
int mx, ix[1<<19];
int findm(int s) {
    int r=0;
    s+=mx;
    while(s) { r+=ix[s]; s>>=1; }
    return r;
}
void inc(int s, int e) {
    s+=mx; e+=mx;
    while(s<=e) {
        if (s&1) { ix[s]++; s++; }
        if ((e&1)==0) {ix[e]++; e--; }
        s>>=1; e>>=1;
    }
}
int main() {
    int n, i, k, ck, s, e, j, nj, d, cc;
    LL b, r, bb, v, t;
    scanf("%d %d", &n, &k);
    for (i=0; i<n; i++) scanf("%d %d", &rs[i].s, &rs[i].e);
    r=1; for (i=1; i<=n; i++) { r*=k; r%=MOD; }
    sort(rs, rs+n, mycmp);
    mx=1; while(mx<=n) mx<<=1;
    memset(ix, 0, sizeof(ix[0])*(mx+mx));
    bb=1;
    for (i=0; i<n; i++) {
        cc = findm(i);
        if (cc>=k) { bb=0; break; }
        bb*=(k-cc); bb%=MOD;
        s=rs[i].s; e=rs[i].e-1;
        j=i; d=n-i; while(d) {
            while(1) {
                nj=j+d; if (nj>=n) break;
                if (rs[nj].s>e) break;
                j=nj;
            }
            d>>=1;
        }
        if (i+1<=j) inc(i+1, j);
    }
    r-=bb; if (r<0) r%=MOD;
    printf("%lld\n", r);
    return 0;
}
0