QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#248890#7627. Phonyucup-team197#WA 2ms11904kbC++174.0kb2023-11-11 22:29:092023-11-11 22:29:09

Judging History

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

  • [2023-11-11 22:29:09]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:11904kb
  • [2023-11-11 22:29:09]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef unsigned long long ull ;
typedef pair < int , int > pii ;
typedef vector < int > vi ;
#define fi first
#define se second
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()

const int MAXN = 5e5 + 7 ;

int n , q ;
ll k ;
ll a[ MAXN ] ;
ll coef[ MAXN ] ;
pair < ll , int > srt[ MAXN ] ;
int rem_ord[ MAXN ] ;

ll high_coef ;
ll cnt_in_cycle ;
int id_next_high ;
int tp ;

class Tree {
public :
    int tr[ 4 * MAXN ] ;
    void init ( int w , int l , int r ) {
        tr[ w ] = 0 ;
        if ( l == r ) { return ; }
        int mid = ( l + r ) / 2 ;
        init ( 2 * w , l , mid ) ;
        init ( 2 * w + 1 , mid + 1 , r ) ;
    }
    void update ( int w , int l , int r , int pos ) {
        ++ tr[ w ] ;
        if ( l == r ) { return ; }
        int mid = ( l + r ) / 2 ;
        if ( pos <= mid ) { update ( 2 * w , l , mid , pos ) ; }
        else { update ( 2 * w + 1 , mid + 1 , r , pos ) ; }
    }
    int query ( int w , int l , int r , int pos ) {
        if ( l == r ) { return srt[ l ].fi ; }
        int mid = ( l + r ) / 2 ;
        if ( tr[ 2 * w + 1 ] >= pos ) { return query ( 2 * w + 1 , mid + 1 , r , pos ) ; }
        else { return query ( 2 * w , l , mid , pos - tr[ 2 * w + 1 ] ) ; }
    }
};

Tree w ;

void solve ( ) {
    cin >> n >> q >> k ;
    for ( int i = 1 ; i <= n ; ++ i ) {
        cin >> a[ i ] ;
    }
    sort ( a + 1 , a + n + 1 ) ;
    for ( int i = 1 ; i <= n ; ++ i ) {
        coef[ i ] = a[ i ] / k ;
        srt[ i ] = { a[ i ] % k , i } ;
    }
    sort ( srt + 1 , srt + n + 1 ) ;
    for ( int i = 1 ; i <= n ; ++ i ) {
        rem_ord[ srt[ i ].se ] = i ;
    }
    tp = n + 1 ;
    high_coef = coef[ n ] ;
    id_next_high = 0 ;
    while ( tp > 1 && coef[ tp - 1 ] == high_coef ) {
        -- tp ;
        ++ cnt_in_cycle ;
        w.update ( 1 , 1 , n , rem_ord[ tp ] ) ;
    }
    while ( q -- ) {
        char type ;
        cin >> type ;
        if ( type == 'C' ) {
            ll cnt ; cin >> cnt ;
            while ( cnt > 0 ) {
                __int128 mxops ;
                if ( cnt_in_cycle == n ) { mxops = cnt + 1 ; }
                else { 
                    mxops = ( high_coef - coef[ tp - 1 ] ) ;
                    mxops *= cnt_in_cycle ;
                    mxops -= id_next_high ;
                }
                if ( mxops >= cnt ) {
                    high_coef -= ( cnt / cnt_in_cycle ) ;
                    cnt %= cnt_in_cycle ;
                    if ( cnt + id_next_high >= cnt_in_cycle ) {
                        -- high_coef ;
                    }
                    id_next_high = ( id_next_high + cnt ) % cnt_in_cycle ;
                    break ;
                }
                else {
                    cnt -= mxops ;
                    high_coef = coef[ tp - 1 ] ;
                    id_next_high = 0 ;
                    while ( tp > 1 && coef[ tp - 1 ] == high_coef ) {
                        -- tp ;
                        ++ cnt_in_cycle ;
                        w.update ( 1 , 1 , n , rem_ord[ tp ] ) ;
                    }
                }
            }
        }
        else {
            int pos ; cin >> pos ;
            if ( pos > cnt_in_cycle ) {
                cout << a[ n - pos + 1 ] << "\n" ;
            }
            else {
                if ( id_next_high + pos <= cnt_in_cycle ) {
                    ll rem = w.query ( 1 , 1 , n , id_next_high + pos ) ;
                    cout << high_coef * k + rem << "\n" ;
                }
                else {
                    ll rem = w.query ( 1 , 1 , n , ( id_next_high + pos - 1 ) % cnt_in_cycle + 1 ) ;
                    cout << ( high_coef - 1 ) * k + rem << "\n" ;
                }
            }
        }
    }
}

int main ( ) {
    ios_base :: sync_with_stdio ( false ) ;
    cin.tie ( NULL ) ;
    int t = 1 ; // cin >> t ;
    while ( t -- ) { solve ( ) ; }
    return 0 ;
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 11904kb

input:

3 5 5
7 3 9
A 3
C 1
A 2
C 2
A 3

output:

3
4
-1

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 11856kb

input:

5 8 8
294 928 293 392 719
A 4
C 200
A 5
C 10
A 2
C 120
A 1
A 3

output:

294
200
191
0
-2

result:

ok 5 lines

Test #3:

score: -100
Wrong Answer
time: 2ms
memory: 11892kb

input:

100 100 233
5101 8001 6561 6329 6305 7745 4321 811 49 1121 3953 8054 8415 9876 6701 4097 6817 6081 495 5521 2389 2042 4721 8119 7441 7840 8001 5756 5561 129 1 5981 4801 7201 8465 7251 6945 5201 5626 3361 5741 3650 7901 2513 8637 3841 5621 9377 101 3661 5105 4241 5137 7501 5561 3581 4901 561 8721 811...

output:

6881
9161
4721
8200
2945
7647
7531
5291
5001
2042
4721
4721
6881
4097
7181
7218
7018
7018
811
6752
2561
6683
6103
6135
3581
5291
1485
5957
5393
2042
5303
5171
5205
4721
5084
4029
4097
4591
4816
4586
4705
2042
4535
4454
4603
4435
3581
4345
115
2042
4284
2042
4274
1485
4326
-17552

result:

wrong answer 15th lines differ - expected: '7187', found: '7181'