結果

問題 No.2220 Range Insert & Point Mex
ユーザー lddlinanlddlinan
提出日時 2023-03-07 21:12:13
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,297 bytes
コンパイル時間 917 ms
コンパイル使用メモリ 91,988 KB
実行使用メモリ 7,632 KB
最終ジャッジ日時 2023-10-18 05:35:58
合計ジャッジ時間 5,121 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,300 KB
testcase_01 AC 2 ms
5,300 KB
testcase_02 AC 2 ms
5,300 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 74 ms
7,520 KB
testcase_24 WA -
testcase_25 AC 56 ms
6,936 KB
testcase_26 AC 60 ms
7,520 KB
testcase_27 AC 36 ms
6,468 KB
testcase_28 AC 24 ms
6,352 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 62 ms
7,632 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
権限があれば一括ダウンロードができます

ソースコード

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 l, r, a; } RNode;
RNode rs[100004];
bool mycmp(const RNode& a, const RNode& b) { return a.a<b.a; }
int xs[100004];
typedef struct { int s, e; } GNode;
GNode gs[100004];
bool mycmp2(const GNode& a, const GNode& b) {
    if (a.s!=b.s) return a.s<b.s;
    return a.e<b.e;
}
int mx, ix[1<<19];
void setm(int s, int e, int v) {
    if (s>e) return;
    s+=mx; e+=mx;
    while(s<=e) {
        if (s&1) { ix[s]=min(ix[s], v); s++; }
        if ((e&1)==0) { ix[e]=min(ix[e], v); e--; }
        s>>=1; e>>=1;
    }
}
int findm(int s) {
    s+=mx;
    int r=ix[s];
    while(s) {
        r=min(r, ix[s]);
        s>>=1;
    }
    return r;
}
int main() {
    int n, i, j, l, r, q, a;
    int inf=0x7fffffff, b, k;
    int s, e, ki, ns, ne;
    scanf("%d", &n);
    for (i=0; i<n; i++) scanf("%d %d %d", &rs[i].l, &rs[i].r, &rs[i].a);
    sort(rs, rs+n, mycmp);
    scanf("%d", &q);
    for (i=0; i<q; i++) scanf("%d", &xs[i]);
    mx=1; while(mx<=q) mx<<=1;
    for (i=0; i<mx+mx; i++) ix[i]=inf;
    b=0;
    for (i=0; i<n; ) {
        a=rs[i].a;
        if (b>a) {
            setm(0, q-1, b);
            break;
        }
        j=i;
        k=0;
        while(j<n&&rs[j].a==a) {
            l=lower_bound(xs, xs+q, rs[j].l)-xs;
            r=upper_bound(xs, xs+q, rs[j].r)-xs; r--;
            // printf("%d: %d,%d\n", j, l, r);
            if (l<=r) { gs[k].s=l;  gs[k].e=r; k++; }
            j++;
        }
        if (k) {
            s=gs[0].s; e=gs[0].e;
            setm(0, s-1, b);
            sort(gs, gs+k, mycmp2);
            for (ki=1; ki<k; ki++) {
                ns=gs[ki].s; ne=gs[ki].e;
                if (ns>e) {
                    setm(e+1, ns-1, b);
                    s=ns; e=ne;
                } else e=max(e, ne);
            }
            setm(e+1, q-1, b);
        }
        i=j;
        b++;
    }
    setm(0, q-1, b);
    for (i=0; i<q; i++) {
        printf("%d\n", findm(i));
    }
    return 0;
}
0