QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#569793 | #9313. Make Max | ksc | TL | 84ms | 53548kb | Java11 | 2.0kb | 2024-09-17 10:52:16 | 2024-09-17 10:52:17 |
Judging History
answer
import java.util.*;
import java.io.*;
public class Main
{
static Scanner sc = new Scanner( System.in );
public static void main( String[] ksc ) throws Exception
{
int t = sc.nextInt();
while( t-- > 0 ) solve();
}
private static void solve() throws Exception
{
int n = sc.nextInt();
long cnt = 0, val = 0;
Queue< r > arr = new LinkedList<>();
for( int i = 0; i < n; i++ )
{
long key = sc.nextLong();
if( val != key )
{
if( cnt != 0 ) arr.add( new r( val, cnt ) );
val = key;
cnt = 1;
} else cnt++;
}
arr.add( new r( val, cnt ) );
long sum = 0;
PriorityQueue< r > pq = new PriorityQueue<>();
int t = arr.size();
for( int i = 0; i < t; i++ )
{
r key = arr.poll();
pq.add( key );
if( !(pq.isEmpty() || pq.peek().v > key.v) )
{
while( pq.peek().v >= key.v )
{
if(pq.size() < 2) break;
r pop = pq.poll();
r update = pq.poll();
update = new r( update.v, update.c + pop.c );
pq.add( update );
sum += pop.c;
}
}
}
while( pq.size() > 1 )
{
r pop = pq.poll();
r update = pq.poll();
update = new r( update.v, update.c + pop.c );
pq.add( update );
sum += pop.c;
}
System.out.println( sum );
}
static class r implements Comparable< r >
{
long c, v;
r( long v, long c )
{
this.v = v;
this.c = c;
}
@Override
public int compareTo( r o )
{
return (int) ( ( this.v - o.v ) % 195329 );
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 84ms
memory: 53548kb
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...
output:
334853