제출 #838813

#제출 시각아이디문제언어결과실행 시간메모리
838813LucaIlieCake 3 (JOI19_cake3)C++17
0 / 100
1 ms224 KiB
#include <bits/stdc++.h> using namespace std; struct ab { int a, b; }; struct event { int type, val, t; }; int m; const int MAX_N = 2e5; const long long INF = 1e18; ab v[MAX_N + 1]; int timee = 0; long long sumA; vector<event> events, newEvents; bool inS[MAX_N + 1]; struct pos { int p; bool operator < ( const pos q ) const { return v[p].a < v[q.p].a; } }; set<pos> s; void insertt( int x ) { inS[x] = true; s.insert( { x } ); sumA += v[x].a; events.push_back( { 1, x, ++timee } ); } void erasee( int x ) { //inS[x] = false; s.erase( { x } ); sumA -= v[x].a; events.push_back( { -1, x, ++timee } ); } void rollback( int t ) { while ( !events.empty() && events.back().t > t ) { int x = events.back().val; /*if ( ok ) printf( "lalla %d %d\n", x, events.back().t );*/ if (events.back().type == 1 ) { inS[x] = false; s.erase( { x } ); sumA -= v[x].a; } else { inS[x] = true; s.insert( { x } ); sumA += v[x].a; } events.pop_back(); } } long long solve( int ll, int lr, int rl, int rr ) { if ( ll > lr || rl > rr ) return -INF; int l = (ll + lr) / 2; long long answer = -INF; int bestR = rr; int t = timee; for ( int i = l; i <= lr && i < rl; i++ ) { insertt( { i } ); if ( s.size() > m ) erasee( s.begin()->p ); } for ( int r = max( l, rl ); r <= rr; r++ ) { insertt( { r } ); if ( s.size() > m ) erasee( s.begin()->p ); if ( s.size() >= m ) { if ( sumA - 2 * (v[r].b - v[l].b) > answer ) { answer = sumA - 2 * (v[r].b - v[l].b); bestR = r; } } } rollback( t ); for ( int i = min( rl - 1, lr ); i >= l; i-- ) { insertt( { i } ); if ( s.size() > m ) erasee( s.begin()->p ); } answer = max( answer, solve( ll, l - 1, rl, bestR ) ); rollback( t ); for ( int i = max( rl, lr + 1 ); i < bestR; i++ ) { insertt( { i } ); if ( s.size() > m ) erasee( s.begin()->p ); } answer = max( answer, solve( l + 1, lr, bestR, rr ) ); rollback( t ); return answer; } int main() { int n; cin >> n >> m; for ( int i = 1; i <= n; i++ ) cin >> v[i].a >> v[i].b; sort( v + 1, v + 1 + n, []( ab x, ab y ) { return x.b < y.b; } ); cout << solve( 1, n, 1, n ); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

cake3.cpp: In function 'long long int solve(int, int, int, int)':
cake3.cpp:76:23: warning: comparison of integer expressions of different signedness: 'std::set<pos>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   76 |         if ( s.size() > m )
      |              ~~~~~~~~~^~~
cake3.cpp:82:23: warning: comparison of integer expressions of different signedness: 'std::set<pos>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   82 |         if ( s.size() > m )
      |              ~~~~~~~~~^~~
cake3.cpp:85:23: warning: comparison of integer expressions of different signedness: 'std::set<pos>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   85 |         if ( s.size() >= m ) {
      |              ~~~~~~~~~^~~~
cake3.cpp:97:23: warning: comparison of integer expressions of different signedness: 'std::set<pos>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   97 |         if ( s.size() > m )
      |              ~~~~~~~~~^~~
cake3.cpp:105:23: warning: comparison of integer expressions of different signedness: 'std::set<pos>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  105 |         if ( s.size() > m )
      |              ~~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...