제출 #288029

#제출 시각아이디문제언어결과실행 시간메모리
2880292qbingxuan마상시합 토너먼트 (IOI12_tournament)C++17
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> #ifdef local #define debug(...) qqbx(#__VA_ARGS__, __VA_ARGS__) template <typename H, typename ...T> void qqbx(const char *s, const H& h, T &&...args) { for(; *s && *s != ','; ++s) if(*s != ' ') std::cerr << *s; std::cerr << " = " << h << (sizeof...(T) ? ", " : "\n"); if constexpr(sizeof...(T)) qqbx(++s, args...); } #define safe std::cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n" #else #define debug(...) ((void)0) #define safe ((void)0) #endif // local #define pb emplace_back #define all(v) begin(v),end(v) using namespace std; vector<pair<int,int>> TransferSE(int S[], int E[], int c, int n) { vector<int> qq(n, 1); vector<int> mx(n); iota(all(mx), 0); vector<pair<int,int>> res; for(int i = 0; i < c; i++) { int cnt = 0; int L = -1, R = -1; for(int j = 0; j < n; j++) if(qq[j]) { if(cnt == S[i]) L = j; else if(cnt == E[i]) R = mx[j]; ++cnt; } for(int j = L+1; j <= R; j++) qq[j] = 0; mx[L] = mx[R]; debug(L, R); assert(L!=-1 && R!=-1); res.pb(L, R); } return res; } struct FenwickTree { int sum[N]; void add(int p, int d) { for(++p; p < N; p+=p&-p) sum[p] += d; } int query(int p) { int r = 0; for(++p; p > 0; p -= p&-p) r += sum[p]; return r; } } fwt; int GetBestPosition(int n, int C, int X, int *K, int *S, int *E) { auto segs = TransferSE(S, E, C, n); safe; vector<tuple<int,bool,int,int>> evt; for(int i = 0; i < C; i++) { auto [l, r] = segs[i]; int mx = -1; for(int j = l; j < r; j++) mx = max(mx, K[j]); debug(l, r, mx); evt.pb(l, 1, i, mx); evt.pb(r, 0, i, mx); } sort(all(evt)); int mx = -1, mxpos = -1; set<int> s; for(int i = 0, j; i < evt.size(); i = j) { for(j = i; j < evt.size(); j++) { if(get<0>(evt[i]) != get<0>(evt[j])) break; auto [_, t, pos, val] = evt[j]; if(t) { if(val > X) s.insert(pos); fwt.add(pos, 1); } else { if(val > X) s.erase(pos); fwt.add(pos, -1); } } int firstLose = s.size() ? *s.begin() : C; int pos = get<0>(evt[i]); int win = query(firstLose-1); if(win > mx) { mx = win; mxpos = pos; } } return mxpos; }

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

tournament.cpp:43:13: error: 'N' was not declared in this scope
   43 |     int sum[N];
      |             ^
tournament.cpp: In member function 'void FenwickTree::add(int, int)':
tournament.cpp:45:22: error: 'N' was not declared in this scope
   45 |         for(++p; p < N; p+=p&-p) sum[p] += d;
      |                      ^
tournament.cpp:45:34: error: 'sum' was not declared in this scope
   45 |         for(++p; p < N; p+=p&-p) sum[p] += d;
      |                                  ^~~
tournament.cpp: In member function 'int FenwickTree::query(int)':
tournament.cpp:49:41: error: 'sum' was not declared in this scope
   49 |         for(++p; p > 0; p -= p&-p) r += sum[p];
      |                                         ^~~
tournament.cpp: In function 'int GetBestPosition(int, int, int, int*, int*, int*)':
tournament.cpp:68:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::tuple<int, bool, int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |     for(int i = 0, j; i < evt.size(); i = j) {
      |                       ~~^~~~~~~~~~~~
tournament.cpp:69:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::tuple<int, bool, int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |         for(j = i; j < evt.size(); j++) {
      |                    ~~^~~~~~~~~~~~
tournament.cpp:82:19: error: 'query' was not declared in this scope
   82 |         int win = query(firstLose-1);
      |                   ^~~~~