Submission #1015419

#TimeUsernameProblemLanguageResultExecution timeMemory
1015419cadmiumskyTeams (IOI15_teams)C++17
0 / 100
4062 ms99096 KiB
#include "teams.h" #include <bits/stdc++.h> #define all(x) (x).begin(),(x).end() using namespace std; using ll = long long; using ld = long double; //#define int ll #define sz(x) ((int)(x).size()) using pii = pair<int,int>; using tii = tuple<int,int,int>; #define lsb(x) (x & -x) struct AIB { int faking = 1; vector<int> nrm; vector<int> tree; AIB(): faking(1) { nrm.clear(); tree.clear(); } void upd(int p, int x) { if(faking) { nrm.emplace_back(p); return; } p = distance(begin(nrm), upper_bound(all(nrm), p)); while(p > 0) tree[p] += x, p -= lsb(p); return; } int query(int p) { int sum = 0; assert(!faking); p = distance(begin(nrm), lower_bound(all(nrm), p)) + 1; while(p < sz(tree)) sum += tree[p], p += lsb(p); return sum; } void donefaking() { faking = 0; sort(all(nrm)); nrm.erase(unique(all(nrm)), end(nrm)); tree.resize(sz(nrm) + 2, 0); } }; struct AIB2D { vector<AIB> tree; void init(int n) { tree.assign(n + 2, AIB()); } int query(int l, int r) { int sum = 0; while(l > 0) { sum += tree[l].query(r); l -= lsb(l); } return sum; } void upd(int l, int r, int x) { while(l < sz(tree)) tree[l].upd(r, x), l += lsb(l); return; } void donefaking() { for(auto &x : tree) x.donefaking(); } }; AIB2D sums; vector<pii> pula; int Query(int x) { int cnt = 0; for(auto [a, b] : pula) if(a <= x && x <= b) cnt++; return cnt; int a = sums.query(x, x); return a; } int Query(int x, int not_y) { int cnt = 0; for(auto [a, b] : pula) if(a <= x && x <= b && !(a <= not_y && not_y <= b)) cnt++; return cnt; return sums.query(x, x) - sums.query(x, not_y); } void init(int n, int A[], int B[]) { sums.init(n + 1); for(int i = 0; i < n; i++) pula.emplace_back(A[i], B[i]), sums.upd(A[i], B[i], 1); sums.donefaking(); for(int i = 0; i < n; i++) sums.upd(A[i], B[i], 1); return; } int can(int M, int K[]) { int sofar = 0; sort(K, K + M); for(int i = 0; i < M; i++) { if(min(0, sofar) + Query(K[i]) - K[i] < 0) return 0; if(i != M - 1) sofar = min(sofar, 0) + Query(K[i], K[i + 1]) - K[i]; } return 1; }

Compilation message (stderr)

teams.cpp: In member function 'void AIB::upd(int, int)':
teams.cpp:23:19: warning: conversion from 'std::__iterator_traits<__gnu_cxx::__normal_iterator<int*, std::vector<int> >, void>::difference_type' {aka 'long int'} to 'int' may change value [-Wconversion]
   23 |       p = distance(begin(nrm), upper_bound(all(nrm), p));
      |           ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
teams.cpp: In member function 'int AIB::query(int)':
teams.cpp:30:58: warning: conversion from 'std::__iterator_traits<__gnu_cxx::__normal_iterator<int*, std::vector<int> >, void>::difference_type' {aka 'long int'} to 'int' may change value [-Wconversion]
   30 |       p = distance(begin(nrm), lower_bound(all(nrm), p)) + 1;
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...