QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#569793#9313. Make MaxkscTL 84ms53548kbJava112.0kb2024-09-17 10:52:162024-09-17 10:52:17

Judging History

你现在查看的是最新测评结果

  • [2024-09-18 15:56:24]
  • hack成功,自动添加数据
  • (/hack/836)
  • [2024-09-17 10:52:17]
  • 评测
  • 测评结果:TL
  • 用时:84ms
  • 内存:53548kb
  • [2024-09-17 10:52:16]
  • 提交

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

result: