Submission #787081

#TimeUsernameProblemLanguageResultExecution timeMemory
787081GusterGoose27Teams (IOI15_teams)C++17
100 / 100
3286 ms364420 KiB
#include "teams.h" #include <bits/stdc++.h> using namespace std; typedef pair<int, int> pii; typedef long long ll; const int MAXN = 5e5+5; pii students[MAXN]; int n; class stree { public: int sum = 0; stree *l = nullptr; stree *r = nullptr; stree(int lp, int rp) { if (lp < rp) { int mid = (lp+rp)/2; l = new stree(lp, mid); r = new stree(mid+1, rp); } } stree(stree *prv) { sum = prv->sum+1; } stree(stree *l, stree *r) : l(l), r(r) { sum = l->sum + r->sum; } stree *upd(int p, int lp = 0, int rp = n-1) { if (lp > p || rp < p) return this; if (lp == rp) { return new stree(this); } int mid = (lp+rp)/2; return new stree(l->upd(p, lp, mid), r->upd(p, mid+1, rp)); } int query(int lv, int rv, int lp = 0, int rp = n-1) { if (lp > rv || rp < lv) return 0; if (lp >= lv && rp <= rv) return sum; int mid = (lp+rp)/2; return l->query(lv, rv, lp, mid)+r->query(lv, rv, mid+1, rp); } }; stree *trees[MAXN]; void init(int N, int A[], int B[]) { n = N; for (int i = 0; i < n; i++) { students[i] = pii(A[i]-1, B[i]-1); } sort(students, students+n); trees[0] = new stree(0, n-1); int j = 0; for (int i = 0; i < n; i++) { trees[i+1] = trees[i]; while (j < n && students[j].first == i) trees[i+1] = trees[i+1]->upd(students[j++].second); } } int sum(int x0, int x1, int y0, int y1) { return trees[x1+1]->query(y0, y1)-trees[x0]->query(y0, y1); } int can(int m, int k[]) { sort(k, k+m); vector<pii> vals; ll s = 0; for (int i = 0; i < m; i++) { s += k[i]; if (vals.empty() || vals.back().first != k[i]-1) { vals.push_back(pii(k[i]-1, 0)); } vals.back().second += k[i]; } if (s > n) return 0; assert(vals.size()*vals.size() <= 2*n); m = vals.size(); vals.push_back(pii(n, 0)); vector<int> sub(m, 0); // gap between this and next for (int i = 0; i < m; i++) { for (int j = i; j < m && vals[i].second > 0; j++) { int cur = min(vals[i].second, sum(0, vals[i].first, vals[j].first, vals[j+1].first-1)-sub[j]); sub[j] += cur; vals[i].second -= cur; } if (vals[i].second > 0) return 0; } return 1; }

Compilation message (stderr)

teams.cpp: In constructor 'stree::stree(stree*, stree*)':
teams.cpp:29:25: warning: declaration of 'r' shadows a member of 'stree' [-Wshadow]
   29 |  stree(stree *l, stree *r) : l(l), r(r) {
      |                  ~~~~~~~^
teams.cpp:18:9: note: shadowed declaration is here
   18 |  stree *r = nullptr;
      |         ^
teams.cpp:29:15: warning: declaration of 'l' shadows a member of 'stree' [-Wshadow]
   29 |  stree(stree *l, stree *r) : l(l), r(r) {
      |        ~~~~~~~^
teams.cpp:17:9: note: shadowed declaration is here
   17 |  stree *l = nullptr;
      |         ^
teams.cpp: In constructor 'stree::stree(stree*, stree*)':
teams.cpp:29:25: warning: declaration of 'r' shadows a member of 'stree' [-Wshadow]
   29 |  stree(stree *l, stree *r) : l(l), r(r) {
      |                  ~~~~~~~^
teams.cpp:18:9: note: shadowed declaration is here
   18 |  stree *r = nullptr;
      |         ^
teams.cpp:29:15: warning: declaration of 'l' shadows a member of 'stree' [-Wshadow]
   29 |  stree(stree *l, stree *r) : l(l), r(r) {
      |        ~~~~~~~^
teams.cpp:17:9: note: shadowed declaration is here
   17 |  stree *l = nullptr;
      |         ^
teams.cpp: In constructor 'stree::stree(stree*, stree*)':
teams.cpp:29:25: warning: declaration of 'r' shadows a member of 'stree' [-Wshadow]
   29 |  stree(stree *l, stree *r) : l(l), r(r) {
      |                  ~~~~~~~^
teams.cpp:18:9: note: shadowed declaration is here
   18 |  stree *r = nullptr;
      |         ^
teams.cpp:29:15: warning: declaration of 'l' shadows a member of 'stree' [-Wshadow]
   29 |  stree(stree *l, stree *r) : l(l), r(r) {
      |        ~~~~~~~^
teams.cpp:17:9: note: shadowed declaration is here
   17 |  stree *l = nullptr;
      |         ^
In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from teams.cpp:3:
teams.cpp: In function 'int can(int, int*)':
teams.cpp:80:33: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   80 |  assert(vals.size()*vals.size() <= 2*n);
      |         ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
teams.cpp:81:15: warning: conversion from 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   81 |  m = vals.size();
      |      ~~~~~~~~~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...