Submission #606677

#TimeUsernameProblemLanguageResultExecution timeMemory
6066778e7Teams (IOI15_teams)C++17
0 / 100
1065 ms524288 KiB
//Challenge: Accepted #include <bits/stdc++.h> using namespace std; #ifdef zisk void debug(){cout << endl;} template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);} template<class T> void pary(T l, T r){ while (l != r) cout << *l << " ", l++; cout << endl; } #else #define debug(...) 0 #define pary(...) 0 #endif #define ll long long #define maxn 500005 #define pii pair<int, int> #define ff first #define ss second #include "teams.h" struct segtree{ vector<int> seg[4*maxn], tol[2*maxn], tor[2*maxn]; void build(int cur, int l, int r, vector<pii> a) { if (r <= l || a.size() == 0) return; if (r - l == 1) { for (auto p:a) seg[cur].push_back(p.ss); sort(seg[cur].begin(), seg[cur].end()); return; } int m = (l + r) / 2; vector<pii> lef, rig; for (auto p:a) { if (p.ff < m)lef.push_back(p); else rig.push_back(p); } build(cur*2, l, m, lef), build(cur*2+1, m, r, rig); int ls = seg[cur*2].size(), rs = seg[cur*2+1].size(); vector<int> &le = seg[cur*2], &ri = seg[cur*2+1]; int ind = 0; for (int i = 0;i < ls;i++) { while (ind < rs && ri[ind] < le[i]) { tol[cur].push_back(i); tor[cur].push_back(ind); seg[cur].push_back(ri[ind++]); } tol[cur].push_back(i); tor[cur].push_back(ind); seg[cur].push_back(le[i]); } while (ind < rs) { tol[cur].push_back(ls); tor[cur].push_back(ind); seg[cur].push_back(ri[ind++]); } tol[cur].push_back(ls); tor[cur].push_back(rs); } int query(int cur, int l, int r, int ql, int qr, int ind) { //number of segments covering [ql, qr] if (r <= l || l > ql) return 0; if (cur == 1) { ind = lower_bound(seg[cur].begin(), seg[cur].end(), qr) - seg[cur].begin(); } if (r-1 <= ql) { return (int)seg[cur].size() - ind; } int m = (l + r) / 2; return query(cur*2, l, m, ql, qr, tol[cur][ind]) + query(cur*2+1, m, r, ql, qr, tor[cur][ind]); } } tr; int v[maxn]; int n; void init(signed N, signed A[], signed B[]) { n = N; vector<pii> a(n); for (int i = 0;i < n;i++) { a[i] = {A[i], B[i]}; v[A[i]]++; v[B[i] + 1]--; } tr.build(1, 1, N+1, a); for (int i = 1;i <= n;i++) v[i] += v[i-1]; //number of segments covering i } signed can(signed m, signed num[]) { sort(num, num + m); vector<int> c(m, 0), dp(m, 0); int tot = 0; for (int i = 0;i < m;i++) { tot += num[i]; c[i] = v[num[i]] - num[i]; dp[i] = c[i]; if (c[i] < 0 || tot > n) return 0; } vector<int> stk; auto f = [&] (int l, int r){ return c[r] + dp[l] - tr.query(1, 1, n+1, num[l], num[r], 0); }; for (int i = 0;i < m;i++) { while (stk.size() > 1 && f(stk.back(), i) > f(stk[stk.size()-2], i)) stk.pop_back(); if (stk.size()) { dp[i] = min(dp[i], f(stk.back(), i)); if (dp[i] < 0) return 0; } stk.push_back(i); } return 1; } /* 4 2 3 1 1 3 4 4 4 1 4 */

Compilation message (stderr)

teams.cpp: In member function 'void segtree::build(int, int, int, std::vector<std::pair<int, int> >)':
teams.cpp:38:27: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   38 |   int ls = seg[cur*2].size(), rs = seg[cur*2+1].size();
      |            ~~~~~~~~~~~~~~~^~
teams.cpp:38:53: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   38 |   int ls = seg[cur*2].size(), rs = seg[cur*2+1].size();
      |                                    ~~~~~~~~~~~~~~~~~^~
teams.cpp: In member function 'int segtree::query(int, int, int, int, int, int)':
teams.cpp:63:60: warning: conversion from '__gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type' {aka 'long int'} to 'int' may change value [-Wconversion]
   63 |    ind = lower_bound(seg[cur].begin(), seg[cur].end(), qr) - seg[cur].begin();
      |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...