답안 #618052

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
618052 2022-08-01T20:32:24 Z chonka Worst Reporter 3 (JOI18_worst_reporter3) C++
100 / 100
618 ms 29380 KB
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
// mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

const int MAXN = 5e5 + 7 ;
const int inf = 1e9 + 7 ;
int n , q ;
ll d[ MAXN ] , hh[ MAXN ] ;


ll eval ( int i , int t ) {
    if ( i == 0 ) { return t ; }
    ll lst = ( t / hh[ i ] ) * hh[ i ] ;
    return lst - i ;
}

int f ( int mn , int t ) {
    int l , r , mid ;
    if ( eval ( 0 , t ) < mn ) { return 0 ; }
    if ( eval ( n , t ) >= mn ) { return n + 1 ; }
    l = 0 , r = n ;
    while ( r - l > 3 ) {
        mid = ( l + r ) / 2 ;
        if ( eval ( mid , t ) >= mn ) { l = mid ; }
        else { r = mid - 1 ; }
    }
    while ( eval ( r , t ) < mn ) { -- r ; }
    return ( r + 1 ) ;
}

void solve ( ) {
    cin >> n >> q ;
    for ( int i = 1 ; i <= n ; ++ i ) {
        cin >> d[ i ] ;
    }
    hh[ 1 ] = d[ 1 ] ;
    for ( int i = 2 ; i <= n ; ++ i ) {
        ll l , r , mid ;
        l = 0 , r = inf ;
        while ( r - l > 3 ) {
            mid = ( l + r ) / 2 ;
            if ( -i + d[ i ] < eval ( i - 1 , mid ) ) { r = mid ; }
            else { l = mid ; }
        }
        while ( l < inf && -i + d[ i ] >= eval ( i - 1 , l ) ) { ++ l ; }
        hh[ i ] = l ;
    }
    while ( q -- ) {
        int st , en , t ;
        cin >> t >> st >> en ;
        cout << f ( st , t ) - f ( en + 1 , t ) << "\n" ;
    }
}

int main ( ) {
    ios_base :: sync_with_stdio ( false ) ;
    cin.tie ( NULL ) ;
    int t = 1 ; // cin >> t ; 
    while ( t -- ) { solve ( ) ; }
    return 0 ;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 614 ms 26620 KB Output is correct
2 Correct 617 ms 26552 KB Output is correct
3 Correct 603 ms 26660 KB Output is correct
4 Correct 600 ms 26652 KB Output is correct
5 Correct 597 ms 26592 KB Output is correct
6 Correct 618 ms 26624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 360 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 614 ms 26620 KB Output is correct
2 Correct 617 ms 26552 KB Output is correct
3 Correct 603 ms 26660 KB Output is correct
4 Correct 600 ms 26652 KB Output is correct
5 Correct 597 ms 26592 KB Output is correct
6 Correct 618 ms 26624 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 360 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 380 ms 25096 KB Output is correct
14 Correct 376 ms 25724 KB Output is correct
15 Correct 359 ms 24460 KB Output is correct
16 Correct 379 ms 24864 KB Output is correct
17 Correct 483 ms 29220 KB Output is correct
18 Correct 473 ms 29148 KB Output is correct
19 Correct 469 ms 29132 KB Output is correct
20 Correct 470 ms 29212 KB Output is correct
21 Correct 468 ms 29132 KB Output is correct
22 Correct 461 ms 29380 KB Output is correct
23 Correct 484 ms 29112 KB Output is correct
24 Correct 469 ms 29216 KB Output is correct
25 Correct 612 ms 26572 KB Output is correct
26 Correct 587 ms 26572 KB Output is correct
27 Correct 509 ms 28728 KB Output is correct
28 Correct 506 ms 29004 KB Output is correct
29 Correct 508 ms 28604 KB Output is correct
30 Correct 503 ms 28740 KB Output is correct
31 Correct 524 ms 28868 KB Output is correct
32 Correct 503 ms 25228 KB Output is correct
33 Correct 0 ms 212 KB Output is correct