Submission #1033202

#TimeUsernameProblemLanguageResultExecution timeMemory
1033202Dan4LifeTeams (IOI15_teams)C++17
34 / 100
4038 ms85700 KiB
#pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,sse4") #include <bits/stdc++.h> using namespace std; #define pb push_back #define sz(a) (int)a.size() #define all(a) begin(a),end(a) using ar2 = array<int,2>; const int mxN = (int)5e5+10; const int mxM = (int)2e5+10; ar2 v[mxN]; int n; multiset<int> S; const int B = 600; const int mxLg = __lg(mxN)+1; const int mxSeg = mxN*4*mxLg; int a[mxN], b[mxN]; int seg[mxSeg], L[mxSeg], R[mxSeg], root[mxSeg]; int segNodes = 1; template<class T> using V = vector<T>; using pi = pair<int,int>; template<class T, int SZ> class OffBIT2D { bool initialized = 0; V<int> all_y; int y_cnt[SZ]{}; int y_start[SZ]{}; V<T> bit; int rank_of_y(int x, int y) { // get rank of y in distinct y-values for x int l = y_start[x], r = y_start[x]+y_cnt[x]; return upper_bound(begin(all_y)+l,begin(all_y)+r,y)-begin(all_y)-l; } public: // all updates {x,y} must satisfy x in (0, SZ), no restrictions on y void init(V<pair<int,int>> updates) { assert(!initialized); initialized = true; sort(begin(updates), end(updates),[](const pi& a, const pi& b) { return a.second < b.second; }); for (auto [x, y]: updates) // push to log(N) different BITs for (; x < SZ; x += x&-x) ++y_cnt[x]; int total_size = 0; for (int i = 0; i < SZ; ++i) y_start[i] = (total_size += y_cnt[i]); all_y.resize(total_size), bit.resize(total_size); reverse(begin(updates), end(updates)); for (auto [x, y]: updates) for (; x < SZ; x += x&-x) all_y[--y_start[x]] = y; } void upd(int x, int _y, T t) { assert(initialized); for (; x < SZ; x += x&-x) for (int y = rank_of_y(x,_y); y <= y_cnt[x]; y += y&-y) bit[y_start[x]+y-1] += t; } T sum(int x, int _y) { assert(initialized); T res = 0; for (; x; x -= x&-x) for (int y = rank_of_y(x,_y); y; y -= y&-y) res += bit[y_start[x]+y-1]; return res; } T sum(int xl, int xr, int yl, int yr) { return sum(xr,yr)-sum(xl-1,yr)-sum(xr,yl-1)+sum(xl-1,yl-1); } }; OffBIT2D<int,mxN> fen2d; void init(int N, int A[], int B[]) { n = N; for(int i = 0; i < n; i++) a[i]=A[i],b[i]=B[i]; for(int i = 0; i < n; i++) v[i]={a[i],b[i]}; V<pi> updates(N); for(int i = 0; i < n; i++) updates[i]={a[i],b[i]}; fen2d.init(updates); for(auto [x,y] : updates) fen2d.upd(x,y,1); sort(v,v+n,[&](ar2 x, ar2 y){ return x[1]>y[1]; }); } int dp[B+10]; int can(int m, int a[]) { sort(a,a+m); if(m>=B){ reverse(a,a+m); int j = 0; S.clear(); for(int i = 0; i < m; i++){ int x = a[i]; while(j<n and v[j][1]>=a[i]) S.insert(v[j][0]), j++; while(x--){ auto itr = S.upper_bound(a[i]); if(itr==begin(S)) return 0; S.erase(--itr); } } return 1; } for(int i = 0; i < m; i++){ dp[i] = fen2d.sum(1,a[i],a[i],n); for(int j = i-1; j>=0; j--) dp[i] = min(dp[i], dp[j]+fen2d.sum(a[j]+1,a[i],a[i],n)); dp[i]-=a[i]; if(dp[i]<0) return 0; } return 1; }

Compilation message (stderr)

teams.cpp: In lambda function:
teams.cpp:38:63: warning: declaration of 'b' shadows a global declaration [-Wshadow]
   38 |   sort(begin(updates), end(updates),[](const pi& a, const pi& b) {
      |                                                     ~~~~~~~~~~^
teams.cpp:16:13: note: shadowed declaration is here
   16 | int a[mxN], b[mxN];
      |             ^
teams.cpp:38:50: warning: declaration of 'a' shadows a global declaration [-Wshadow]
   38 |   sort(begin(updates), end(updates),[](const pi& a, const pi& b) {
      |                                        ~~~~~~~~~~^
teams.cpp:16:5: note: shadowed declaration is here
   16 | int a[mxN], b[mxN];
      |     ^
teams.cpp: In function 'void init(int, int*, int*)':
teams.cpp:73:31: warning: declaration of 'B' shadows a global declaration [-Wshadow]
   73 | void init(int N, int A[], int B[]) {
      |                           ~~~~^~~
teams.cpp:13:11: note: shadowed declaration is here
   13 | const int B = 600;
      |           ^
teams.cpp: In function 'int can(int, int*)':
teams.cpp:84:20: warning: declaration of 'a' shadows a global declaration [-Wshadow]
   84 | int can(int m, int a[]) {
      |                ~~~~^~~
teams.cpp:16:5: note: shadowed declaration is here
   16 | int a[mxN], b[mxN];
      |     ^
teams.cpp: In instantiation of 'void OffBIT2D<T, SZ>::init(V<std::pair<int, int> >) [with T = int; int SZ = 500010; V<std::pair<int, int> > = std::vector<std::pair<int, int>, std::allocator<std::pair<int, int> > >]':
teams.cpp:79:20:   required from here
teams.cpp:38:63: warning: declaration of 'b' shadows a global declaration [-Wshadow]
   38 |   sort(begin(updates), end(updates),[](const pi& a, const pi& b) {
      |                                                     ~~~~~~~~~~^
teams.cpp:16:13: note: shadowed declaration is here
   16 | int a[mxN], b[mxN];
      |             ^
teams.cpp:38:50: warning: declaration of 'a' shadows a global declaration [-Wshadow]
   38 |   sort(begin(updates), end(updates),[](const pi& a, const pi& b) {
      |                                        ~~~~~~~~~~^
teams.cpp:16:5: note: shadowed declaration is here
   16 | int a[mxN], b[mxN];
      |     ^
teams.cpp: In instantiation of 'int OffBIT2D<T, SZ>::rank_of_y(int, int) [with T = int; int SZ = 500010]':
teams.cpp:56:17:   required from 'void OffBIT2D<T, SZ>::upd(int, int, T) [with T = int; int SZ = 500010]'
teams.cpp:79:64:   required from here
teams.cpp:31:67: warning: conversion from '__gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type' {aka 'long int'} to 'int' may change value [-Wconversion]
   31 |   return upper_bound(begin(all_y)+l,begin(all_y)+r,y)-begin(all_y)-l;
      |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...