QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#568871 | #9313. Make Max | yingxueyuhanling | TL | 45ms | 39236kb | Java8 | 1.7kb | 2024-09-16 18:59:15 | 2024-09-16 18:59:18 |
Judging History
answer
import java.io.*;
import java.util.*;
public class Main {
static PrintWriter out=new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
static StreamTokenizer in=new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
static HashMap<Integer, List<Integer>> map=new HashMap<>();
static TreeSet<Integer> set=new TreeSet<>();
static int[] arr=new int[200000+5];
public static void main(String[] args) throws IOException {
in.nextToken();int t=(int)in.nval;
while(t-->0){
map.clear();
set.clear();
in.nextToken();int n=(int)in.nval;
for(int i=0;i<n;i++){
in.nextToken();arr[i]=(int)in.nval;
if(!map.containsKey(arr[i])){
map.put(arr[i],new ArrayList<>());
set.add(arr[i]);
}
map.get(arr[i]).add(i);
}
long cnt=0;
for(Integer temp:set){
for(int i=0;i<map.get(temp).size();i++){
int left=map.get(temp).get(i),right=map.get(temp).get(i);
while(right<n-1&& arr[right]==arr[right+1]){
right++;
}
while(left>=1&& arr[left]==arr[left-1]){
left--;
}
if(left-1<0&&right+1>=n){
break;
}else if(left-1<0||right+1>=n){
cnt+=right-left+1;
int min=left-1<0?right+1:left-1;
for(int j=left;j<=right;j++){
arr[j]=arr[min];
}
}else{
cnt+=right-left+1;
int min=Math.min(arr[left-1],arr[right+1]);
for(int j=left;j<=right;j++){
arr[j]=min;
}
}
}
}
out.println(cnt);
}
out.close();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 45ms
memory: 39236kb
input:
4 2 1 2 2 2 2 7 1 1 1 2 2 2 2 3 1 2 3
output:
1 0 3 3
result:
ok 4 number(s): "1 0 3 3"
Test #2:
score: -100
Time Limit Exceeded
input:
2 198018 875421126 585870339 471894633 383529988 625397685 944061047 704695631 105113224 459022561 760848605 980735314 847376362 980571959 329939331 644635272 326439858 752879510 837384394 175179068 182094523 397239381 1199016 185143405 279638454 252374970 822030887 860312140 137248166 993229443 164...