Submission #133245

#TimeUsernameProblemLanguageResultExecution timeMemory
133245DodgeBallManSails (IOI07_sails)C++14
5 / 100
46 ms2792 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...