Submission #588487

#TimeUsernameProblemLanguageResultExecution timeMemory
588487lorenzoferrariTeams (IOI15_teams)C++17
0 / 100
3420 ms58448 KiB
#include "teams.h" #include <bits/stdc++.h> using namespace std; int n; vector<vector<int>> ft; int count(vector<vector<int>*> v, int l, int r) { // return elements in [l, r] int ans = 0; for (auto p : v) { ans += upper_bound(p->begin(), p->end(), r) - upper_bound(p->begin(), p->end(), l-1); } return ans; } vector<vector<int>*> get_prefix(int a) { vector<vector<int>*> ans; for (; a > 0; a -= (a & -a)) { ans.push_back(&ft[a]); } return ans; } int can(int M, int K[]) { // cerr << "query: \n"; sort(K, K + M); int delta = 0; for (int i = 0; i < M; ++i) { auto p = get_prefix(K[i]); // for (auto x : p) for (auto y : *x) cerr << y << " "; // cerr << endl; int l = K[i]-1, r = n; while (r - l > 1) { int m = (l + r) / 2; if (count(p, K[i], m) >= K[i] + delta) { r = m; } else { l = m; } } if (count(p, K[i], r) < K[i] + delta) return 0; if (i != M-1) { if (K[i+1] > r) { delta = 0; } else { int r_used = K[i] + delta - count(p, K[i], r-1); delta = count(p, K[i+1], r-1) + r_used; } } } return 1; } void init(int n, int a[], int b[]) { ::n = n; ft.resize(n + 1); for (int i = 0; i < n; ++i) { for (int j = a[i]; j <= n; j += (j & -j)) { ft[j].push_back(b[i]); } } for (int i = 1; i <= n; ++i) { sort(ft[i].begin(), ft[i].end()); } }

Compilation message (stderr)

teams.cpp: In function 'int count(std::vector<std::vector<int>*>, int, int)':
teams.cpp:13:49: warning: conversion from '__gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type' {aka 'long int'} to 'int' may change value [-Wconversion]
   13 |            upper_bound(p->begin(), p->end(), l-1);
      |                                                 ^
teams.cpp: In function 'void init(int, int*, int*)':
teams.cpp:56:15: warning: declaration of 'n' shadows a global declaration [-Wshadow]
   56 | void init(int n, int a[], int b[]) {
      |           ~~~~^
teams.cpp:5:5: note: shadowed declaration is here
    5 | int n;
      |     ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...