結果

問題 No.1675 Strange Minimum Query
ユーザー merlinmerlin
提出日時 2021-09-10 22:13:34
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,300 bytes
コンパイル時間 5,063 ms
コンパイル使用メモリ 80,420 KB
実行使用メモリ 85,932 KB
最終ジャッジ日時 2023-09-02 18:09:24
合計ジャッジ時間 30,490 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 38 ms
33,808 KB
testcase_02 WA -
testcase_03 AC 797 ms
63,344 KB
testcase_04 AC 769 ms
62,848 KB
testcase_05 AC 270 ms
47,884 KB
testcase_06 AC 934 ms
64,904 KB
testcase_07 AC 955 ms
68,944 KB
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 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
権限があれば一括ダウンロードができます

ソースコード

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[q][3],i;
        Queue<int[]> g[]=new LinkedList[n];
        for(i=0;i<n;i++) g[i]=new LinkedList<>();
        for(i=0;i<q;i++)
        {
            s=bu.readLine().split(" ");
            for(int j=0;j<3;j++) a[i][j]=Integer.parseInt(s[j]);
            a[i][0]--;
            g[a[i][0]].add(new int[]{a[i][1],a[i][2]});
        }

        PriorityQueue<int[]> pq=new PriorityQueue<>(new Comparator<int[]>() {
            @Override
            public int compare(int[] o1, int[] o2) {
                if(o1[0]>o2[0]) return 1;
                else return -1;
            }});
        int ans[]=new int[n];
        for(i=0;i<n;i++)
        {
            while(!pq.isEmpty() && pq.peek()[0]<=i) pq.poll();
            while(!g[i].isEmpty()) pq.add(g[i].poll());
            if(!pq.isEmpty()) ans[i]=pq.poll()[1];
            else if(i>0) ans[i]=ans[i-1];
        }
        for(i=n-2;i>=0;i--)
        if(ans[i]==0) ans[i]=ans[i+1];

        st=new int[4*n];
        Arrays.fill(st,Integer.MAX_VALUE);
        for(i=0;i<n;i++) update(0,n-1,i,ans[i],0);

        boolean pos=true;
        for(i=0;i<q && pos;i++)
        pos&=query(0,n-1,a[i][0],a[i][1]-1,0)==a[i][2];
        if(pos)
        for(i=0;i<n;i++) sb.append(ans[i]+" ");
        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