제출 #637405

#제출 시각아이디문제언어결과실행 시간메모리
637405MohamedFaresNebili팀들 (IOI15_teams)C++14
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> #pragma GCC optimize ("Ofast") #pragma GCC target ("avx2") ///#include "teams.h" using namespace std; const int INF = INT32_MAX; int N, C[500005], A[500005], B[500005]; vector<int> P[500005]; struct node { int val; node *l, *r; node() { l = nullptr, r = nullptr; val = 0; } node(int x) : val(x), l(nullptr), r(nullptr) {} node(node *ll, node *rr) { l = ll, r = rr; val = 0; if (l) val += l->val; if (r) val += r->val; } node(node *cp) : val(cp->val), l(cp->l), r(cp->r) {} }; node* ST[500005]; node* update(node* v, int l, int r, int pos, int x) { if (l == r) return new node(v->val + x); int mid = (l + r) / 2; if (pos > mid) { if(!v->r) v->r = new node(); return new node(v->l, update(v->r, mid + 1, r, pos, x)); } else { if(!v->l) v->l = new node(); return new node(update(v->l, l, mid, pos, x), v->r); } } int query(node* v, int l, int r, int lo, int hi) { if (l > hi || r < lo) return 0; if (l >= lo && r <= hi) return v->val; int md = (l + r) / 2; int a = 0, b = 0; if(v -> l) a = query(v -> l, l, md, lo, hi); if(v -> r) b = query(v -> r, md + 1, r, lo, hi); return a + b; } int query(node* root, int lo, int hi) { return query(root, 1, N, lo, hi); } void init(int n, int a[], int b[]) { N = n; ST[0] = new node(); for(int l = 0; l < N; l++) A[l] = a[l], B[l] = b[l]; for(int l = 0; l < N; l++) P[A[l]].push_back(B[l]); for(int l = 1; l <= N; l++) { ST[l] = new node(ST[l - 1]); for(auto u : P[l]) ST[l] = update(ST[l], 1, N, u, 1); } } int can(int M, int K[]) { long long S = 0; vector<int> V; for(int l = 0; l < M; l++) S += K[l]; if(S > N) return 0; for(int l = 0; l < M; l++) V.push_back(K[l]), C[K[l]]++; sort(V.begin(), V.end()); V.erase(unique(V.begin(), V.end()), V.end()); vector<int> rem(V.size(), 0); for(int i = 0; i < V.size(); i++) { int U = V[i]; int cur = U * C[U]; for(int j = i; j < V.size(); j++) { int hi = (j == V.size() - 1 ? N : V[j + 1] - 1); int calc = min(cur, query(ST[U], V[j], hi) - rem[j]); cur -= calc; rem[j] += calc; if(cur == 0) break; } if(cur > 0) { for(auto u : V) C[u] = 0; return 0; } } for(auto u : V) C[u] = 0; return 1; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; int a[n], b[n]; for(int l = 0; l < n; l++) cin >> a[l] >> b[l]; int q; cin >> q; init(n, a, b); while(q--) { int m; cin >> m; int k[m]; for(int i = 0; i < m; i++) cin >> k[i]; cout << can(m, k) << "\n"; } return 0; }#include <bits/stdc++.h> #pragma GCC optimize ("Ofast") #pragma GCC target ("avx2") ///#include "teams.h" using namespace std; const int INF = INT32_MAX; int N, C[500005], A[500005], B[500005]; vector<int> P[500005]; struct node { int val; node *l, *r; node() { l = nullptr, r = nullptr; val = 0; } node(int x) : val(x), l(nullptr), r(nullptr) {} node(node *ll, node *rr) { l = ll, r = rr; val = 0; if (l) val += l->val; if (r) val += r->val; } node(node *cp) : val(cp->val), l(cp->l), r(cp->r) {} }; node* ST[500005]; node* update(node* v, int l, int r, int pos, int x) { if (l == r) return new node(v->val + x); int mid = (l + r) / 2; if (pos > mid) { if(!v->r) v->r = new node(); return new node(v->l, update(v->r, mid + 1, r, pos, x)); } else { if(!v->l) v->l = new node(); return new node(update(v->l, l, mid, pos, x), v->r); } } int query(node* v, int l, int r, int lo, int hi) { if (l > hi || r < lo) return 0; if (l >= lo && r <= hi) return v->val; int md = (l + r) / 2; int a = 0, b = 0; if(v -> l) a = query(v -> l, l, md, lo, hi); if(v -> r) b = query(v -> r, md + 1, r, lo, hi); return a + b; } int query(node* root, int lo, int hi) { return query(root, 1, N, lo, hi); } void init(int n, int a[], int b[]) { N = n; ST[0] = new node(); for(int l = 0; l < N; l++) A[l] = a[l], B[l] = b[l]; for(int l = 0; l < N; l++) P[A[l]].push_back(B[l]); for(int l = 1; l <= N; l++) { ST[l] = new node(ST[l - 1]); for(auto u : P[l]) ST[l] = update(ST[l], 1, N, u, 1); } } int can(int M, int K[]) { long long S = 0; vector<int> V; for(int l = 0; l < M; l++) S += K[l]; if(S > N) return 0; for(int l = 0; l < M; l++) V.push_back(K[l]), C[K[l]]++; sort(V.begin(), V.end()); V.erase(unique(V.begin(), V.end()), V.end()); vector<int> rem(V.size(), 0); for(int i = 0; i < V.size(); i++) { int U = V[i]; int cur = U * C[U]; for(int j = i; j < V.size(); j++) { int hi = (j == V.size() - 1 ? N : V[j + 1] - 1); int calc = min(cur, query(ST[U], V[j], hi) - rem[j]); cur -= calc; rem[j] += calc; if(cur == 0) break; } if(cur > 0) { for(auto u : V) C[u] = 0; return 0; } } for(auto u : V) C[u] = 0; return 1; }

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

teams.cpp:109:14: error: stray '#' in program
  109 |             }#include <bits/stdc++.h>
      |              ^
teams.cpp: In function 'int can(int, int*)':
teams.cpp:78:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |                 for(int i = 0; i < V.size(); i++) {
      |                                ~~^~~~~~~~~~
teams.cpp:81:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |                     for(int j = i; j < V.size(); j++) {
      |                                    ~~^~~~~~~~~~
teams.cpp:82:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |                         int hi = (j == V.size() - 1 ? N : V[j + 1] - 1);
      |                                   ~~^~~~~~~~~~~~~~~
teams.cpp: At global scope:
teams.cpp:109:15: error: 'include' does not name a type
  109 |             }#include <bits/stdc++.h>
      |               ^~~~~~~
teams.cpp:116:23: error: redefinition of 'const int INF'
  116 |             const int INF = INT32_MAX;
      |                       ^~~
teams.cpp:8:23: note: 'const int INF' previously defined here
    8 |             const int INF = INT32_MAX;
      |                       ^~~
teams.cpp:118:17: error: redefinition of 'int N'
  118 |             int N, C[500005], A[500005], B[500005];
      |                 ^
teams.cpp:10:17: note: 'int N' previously declared here
   10 |             int N, C[500005], A[500005], B[500005];
      |                 ^
teams.cpp:118:20: error: redefinition of 'int C [500005]'
  118 |             int N, C[500005], A[500005], B[500005];
      |                    ^
teams.cpp:10:20: note: 'int C [500005]' previously declared here
   10 |             int N, C[500005], A[500005], B[500005];
      |                    ^
teams.cpp:118:31: error: redefinition of 'int A [500005]'
  118 |             int N, C[500005], A[500005], B[500005];
      |                               ^
teams.cpp:10:31: note: 'int A [500005]' previously declared here
   10 |             int N, C[500005], A[500005], B[500005];
      |                               ^
teams.cpp:118:42: error: redefinition of 'int B [500005]'
  118 |             int N, C[500005], A[500005], B[500005];
      |                                          ^
teams.cpp:10:42: note: 'int B [500005]' previously declared here
   10 |             int N, C[500005], A[500005], B[500005];
      |                                          ^
teams.cpp:119:25: error: redefinition of 'std::vector<int> P [500005]'
  119 |             vector<int> P[500005];
      |                         ^
teams.cpp:11:25: note: 'std::vector<int> P [500005]' previously declared here
   11 |             vector<int> P[500005];
      |                         ^
teams.cpp:121:20: error: redefinition of 'struct node'
  121 |             struct node {
      |                    ^~~~
teams.cpp:13:20: note: previous definition of 'struct node'
   13 |             struct node {
      |                    ^~~~
teams.cpp:137:19: error: redefinition of 'node* ST [500005]'
  137 |             node* ST[500005];
      |                   ^~
teams.cpp:29:19: note: 'node* ST [500005]' previously declared here
   29 |             node* ST[500005];
      |                   ^~
teams.cpp:139:19: error: redefinition of 'node* update(node*, int, int, int, int)'
  139 |             node* update(node* v, int l, int r, int pos, int x) {
      |                   ^~~~~~
teams.cpp:31:19: note: 'node* update(node*, int, int, int, int)' previously defined here
   31 |             node* update(node* v, int l, int r, int pos, int x) {
      |                   ^~~~~~
teams.cpp:152:17: error: redefinition of 'int query(node*, int, int, int, int)'
  152 |             int query(node* v, int l, int r, int lo, int hi) {
      |                 ^~~~~
teams.cpp:44:17: note: 'int query(node*, int, int, int, int)' previously defined here
   44 |             int query(node* v, int l, int r, int lo, int hi) {
      |                 ^~~~~
teams.cpp:163:17: error: redefinition of 'int query(node*, int, int)'
  163 |             int query(node* root, int lo, int hi) { return query(root, 1, N, lo, hi); }
      |                 ^~~~~
teams.cpp:55:17: note: 'int query(node*, int, int)' previously defined here
   55 |             int query(node* root, int lo, int hi) { return query(root, 1, N, lo, hi); }
      |                 ^~~~~
teams.cpp:165:18: error: redefinition of 'void init(int, int*, int*)'
  165 |             void init(int n, int a[], int b[]) {
      |                  ^~~~
teams.cpp:57:18: note: 'void init(int, int*, int*)' previously defined here
   57 |             void init(int n, int a[], int b[]) {
      |                  ^~~~
teams.cpp:177:17: error: redefinition of 'int can(int, int*)'
  177 |             int can(int M, int K[]) {
      |                 ^~~
teams.cpp:69:17: note: 'int can(int, int*)' previously defined here
   69 |             int can(int M, int K[]) {
      |                 ^~~
teams.cpp: In function 'int can(int, int*)':
teams.cpp:186:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  186 |                 for(int i = 0; i < V.size(); i++) {
      |                                ~~^~~~~~~~~~
teams.cpp:189:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  189 |                     for(int j = i; j < V.size(); j++) {
      |                                    ~~^~~~~~~~~~
teams.cpp:190:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  190 |                         int hi = (j == V.size() - 1 ? N : V[j + 1] - 1);
      |                                   ~~^~~~~~~~~~~~~~~