Submission #133245

# Submission time Handle Problem Language Result Execution time Memory
133245 2019-07-20T09:56:46 Z DodgeBallMan Sails (IOI07_sails) C++14
5 / 100
46 ms 2792 KB
#include <bits/stdc++.h>
#define pii pair<int, int>
#define x first
#define y second 

using namespace std;

const int N = 1e5 + 10;
int fen[N], n, k, tod, mh;
vector<pii> v;
long long ans;

void up( int l, int r, int va ) {
    if( l > r ) return;
    for( int i = l ; i < N ; i += ( i & -i ) ) fen[i] += va;
    for( int i = r + 1 ; i < N ; i += ( i & -i ) ) fen[i] -= va;
}

int query( int idx ) {
    int ret = 0;
    for( int i = idx ; i > 0 ; i -= ( i & -i ) ) ret += fen[i];
    return ret;
}
int main()
{
    scanf("%d",&n);
    v.emplace_back( pii( 0, 0 ) );
    for( int i = 1, h, k ; i <= n ; i++ ) {
        scanf("%d %d",&h,&k);
        mh = max( mh, h );
        v.emplace_back( pii( h, k ) );
    }
    sort( v.begin(), v.end() );
    for( int i = ( int )v.size() - 1 ; i > 0 ; i-- ) {
        //printf("v[i].x : %d v[i].y : %d tod : %d\n",v[i].x,v[i].y,tod);
        int know = v[i].y + tod;
        if( know >= v[i].x ) {
            int a = ( know / v[i].x );
            know -= ( v[i].x * a );
            up( 1, v[i].x, a );
        }
        //printf("%d knowwtf\n",know);
        int x = v[i].x - v[i-1].x;
        if( know < x ) up( v[i-1].x + 1, v[i-1].x + know, 1 );
        else up( v[i-1].x + 1, v[i].x, 1 );
        know = max( 0, know - v[i].x + v[i-1].x );
        //printf("know %d\n",know);
        if( know > 0 ) tod = know;
        else tod = 0;
        // for( int j = 1 ; j <= mh ; j++ ) {
        //     long long x = ( long long )query( j );
        //     printf("%lld ",x);
        // }
        // printf("\n");
    }
    for( int i = 1 ; i <= mh ; i++ ) {
        long long x = ( long long )query( i );
        //printf("%lld ",x);
        ans += ( ( x - 1 ) * ( x ) ) / 2;
    }
    printf("%lld",ans);
    return 0;
}

Compilation message

sails.cpp: In function 'int main()':
sails.cpp:26:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
     ~~~~~^~~~~~~~~
sails.cpp:29:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d",&h,&k);
         ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 636 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 1140 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 26 ms 1620 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 35 ms 2288 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 45 ms 2588 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 46 ms 2792 KB Output isn't correct
2 Halted 0 ms 0 KB -