結果
| 問題 |
No.1705 Mode of long array
|
| コンテスト | |
| ユーザー |
merlin
|
| 提出日時 | 2021-10-08 22:54:05 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 636 ms / 3,000 ms |
| コード長 | 1,943 bytes |
| コンパイル時間 | 2,277 ms |
| コンパイル使用メモリ | 79,856 KB |
| 実行使用メモリ | 75,488 KB |
| 最終ジャッジ日時 | 2024-07-23 06:05:19 |
| 合計ジャッジ時間 | 28,091 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 51 |
ソースコード
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 m=Integer.parseInt(s[1]);
a=new long[m+1];
st=new int[4*(m+1)];
long n=Long.parseLong(s[0]);
int i;
s=bu.readLine().split(" ");
for(i=1;i<=m;i++)
{
a[i]=Long.parseLong(s[i-1]);
update(0,m,i,0);
}
int q=Integer.parseInt(bu.readLine());
while(q-->0)
{
s=bu.readLine().split(" ");
int t=Integer.parseInt(s[0]),x=Integer.parseInt(s[1]);
long y=Long.parseLong(s[2]);
if(t==1)
{
a[x]+=y;
update(0,m,x,0);
}
else if(t==2)
{
a[x]-=y;
a[x]=Math.max(a[x],0); //dunno if its needed or not(cant read japanese)
update(0,m,x,0);
}
else
sb.append(query(0,m,0,m,0)+"\n");
}
System.out.print(sb);
}
static int st[];
static long a[];
static void update(int ss,int se,int i,int n)
{
if(ss>se) return;
if(ss==se)
{
st[n]=i;
return;
}
int m=(ss+se)>>1;
if(i<=m) update(ss,m,i,2*n+1);
else update(m+1,se,i,2*n+2);
if(a[st[2*n+1]]>a[st[2*n+2]]) st[n]=st[2*n+1];
else st[n]=st[2*n+2];
}
static int query(int ss,int se,int qs,int qe,int n)
{
if(ss>se || qs>se || qe<ss) return 0;
if(qs<=ss && qe>=se) return st[n];
int m=(ss+se)>>1;
int q1=query(ss,m,qs,qe,2*n+1),q2=query(m+1,se,qs,qe,2*n+2);
if(a[q2]>=a[q1]) return q2;
else return q1;
}
}
merlin