結果

問題 No.1675 Strange Minimum Query
ユーザー merlinmerlin
提出日時 2021-09-10 22:34:23
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,354 ms / 2,000 ms
コード長 2,477 bytes
コンパイル時間 7,031 ms
コンパイル使用メモリ 76,540 KB
実行使用メモリ 96,404 KB
最終ジャッジ日時 2023-09-02 19:07:01
合計ジャッジ時間 40,444 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
49,676 KB
testcase_01 AC 44 ms
49,772 KB
testcase_02 AC 44 ms
50,204 KB
testcase_03 AC 554 ms
68,644 KB
testcase_04 AC 592 ms
75,184 KB
testcase_05 AC 347 ms
65,856 KB
testcase_06 AC 562 ms
70,680 KB
testcase_07 AC 623 ms
77,180 KB
testcase_08 AC 48 ms
49,768 KB
testcase_09 AC 118 ms
53,672 KB
testcase_10 AC 1,175 ms
80,788 KB
testcase_11 AC 454 ms
73,200 KB
testcase_12 AC 1,212 ms
85,356 KB
testcase_13 AC 1,090 ms
92,404 KB
testcase_14 AC 1,261 ms
94,992 KB
testcase_15 AC 1,246 ms
93,732 KB
testcase_16 AC 44 ms
47,824 KB
testcase_17 AC 441 ms
62,316 KB
testcase_18 AC 461 ms
65,412 KB
testcase_19 AC 782 ms
82,816 KB
testcase_20 AC 991 ms
80,748 KB
testcase_21 AC 990 ms
82,196 KB
testcase_22 AC 1,198 ms
88,584 KB
testcase_23 AC 879 ms
72,580 KB
testcase_24 AC 886 ms
77,096 KB
testcase_25 AC 668 ms
66,056 KB
testcase_26 AC 483 ms
65,552 KB
testcase_27 AC 1,073 ms
83,604 KB
testcase_28 AC 665 ms
74,572 KB
testcase_29 AC 638 ms
78,768 KB
testcase_30 AC 535 ms
65,732 KB
testcase_31 AC 935 ms
76,736 KB
testcase_32 AC 1,238 ms
93,804 KB
testcase_33 AC 1,115 ms
96,096 KB
testcase_34 AC 1,123 ms
92,756 KB
testcase_35 AC 1,291 ms
96,368 KB
testcase_36 AC 1,354 ms
96,404 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

class Main
{
    public static void main(String args[])throws Exception
    {
        BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb=new StringBuilder();
        String s[]=bu.readLine().split(" ");
        int n=Integer.parseInt(s[0]),q=Integer.parseInt(s[1]);

        int a[]=new int[3],i;
        st=new int[4*n];
        Arrays.fill(st,Integer.MAX_VALUE);
        int ans[]=new int[n];
        TreeSet<Integer> ts=new TreeSet<>();
        for(i=0;i<n;i++)
        {
            ans[i]=(int)1e9;
            update(0,n-1,i,ans[i],0);
            ts.add(i);
        }

        PriorityQueue<int[]> pq=new PriorityQueue<>(new Comparator<int[]>() {
            @Override
            public int compare(int[] o1, int[] o2) {
                if(o1[2]<o2[2]) return 1;
                else return -1;
            }});
        for(i=0;i<q;i++)
        {
            s=bu.readLine().split(" ");
            for(int j=0;j<3;j++) a[j]=Integer.parseInt(s[j]);
            a[0]--; a[1]--;
            pq.add(new int[]{a[0],a[1],a[2]});
        }

        boolean pos=true;
        while(!pq.isEmpty() && pos)
        {
            a=pq.poll();
            Integer lo=ts.higher(a[0]-1);
            int qe=query(0,n-1,a[0],a[1],0);
            boolean can=qe==a[2];
            while(lo!=null)
            {
                int l=lo;
                if(l>a[1]) break;
                ts.remove(lo);
                can=true;
                ans[l]=a[2];
                update(0,n-1,l,a[2],0);
                lo=ts.higher(lo);
            }
            pos&=can;
        }

        if(pos)
        for(i=0;i<n;i++)
        {
            sb.append(ans[i]);
            if(i<n-1) sb.append(" ");
        }
        else sb.append("-1");
        System.out.println(sb);
    }

    static int st[];
    static void update(int ss,int se,int i,int v,int n)
    {
        if(ss>se) return;
        if(ss==se)
        {
            st[n]=v;
            return;
        }

        int m=(se+ss)/2;
        if(i<=m) update(ss,m,i,v,2*n+1);
        else update(m+1,se,i,v,2*n+2);
        st[n]=Math.min(st[2*n+1],st[2*n+2]);
    }

    static int query(int ss,int se,int qs,int qe,int n)
    {
        if(ss>se || qe<ss || qs>se) return Integer.MAX_VALUE;
        if(qs<=ss && qe>=se) return st[n];

        int m=(se+ss)/2;
        return Math.min(query(ss,m,qs,qe,2*n+1),query(m+1,se,qs,qe,2*n+2));
    }
}
0