제출 #1173674

#제출 시각아이디문제언어결과실행 시간메모리
1173674LucaIlieRope (JOI17_rope)C++20
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> #pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") using namespace std; const int MAX_N = 1e6; const int MAX_M = 1e6; int c[MAX_N], frecv[MAX_M + 1]; vector<int> pos[MAX_M + 1]; priority_queue<pair<int, int>> maxFrecv; int main() { cin.tie( nullptr ); ios_base::sync_with_stdio( false ); int n, m; cin >> n >> m; for ( int i = 0; i < n; i++ ) { cin >> c[i]; frecv[c[i]]++; pos[c[i]].push_back( i ); } if ( m == 1 ) { cout << "0\n"; return 0; } for ( int i = 1; i <= m; i++ ) maxFrecv.push( { frecv[i], i } ); for ( int x = 1; x <= m; x++ ) { int minn = n; for ( int f = 0; f < 2; f++ ) { int changes = 0, sumFrecv = n - frecv[x]; for ( int p: pos[x] ) { int q = ((p - f) % 2 == 0 ? p + 1 : p - 1); if ( f <= q && q < n && c[q] != x ) { frecv[c[q]]--; sumFrecv--; pq.push( frecv[c[q]] ); changes++; } } auto maxx = pq.top(); while ( frecv[maxx.second] != maxx.first ) { pq.pop(); maxx = pq.top(); } auto maxx2 = maxx; while ( frecv[maxx.second] != maxx.first || maxx2.second == x ) { pq.pop(); maxx2 = pq.top(); } changes += sumFrecv - maxx2->first; pq.push( maxx ); minn = min( minn, changes ); for ( int p: pos[x] ) { int q = ((p - f) % 2 == 0 ? p + 1 : p - 1); if ( f <= q && q < n && c[q] != x ) { frecv[c[q]]++; pq.push( frecv[c[q]] ); } } } cout << minn << "\n"; } return 0; }

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

rope.cpp: In function 'int main()':
rope.cpp:45:21: error: 'pq' was not declared in this scope; did you mean 'q'?
   45 |                     pq.push( frecv[c[q]] );
      |                     ^~
      |                     q
rope.cpp:50:25: error: 'pq' was not declared in this scope
   50 |             auto maxx = pq.top();
      |                         ^~