Submission #384592

#TimeUsernameProblemLanguageResultExecution timeMemory
384592luciocfTeams (IOI15_teams)C++14
0 / 100
4120 ms357868 KiB
#include <bits/stdc++.h> #include "teams.h" #define ff first #define ss second using namespace std; typedef pair<int, int> pii; typedef long long ll; const int maxn = 5e5+10; int n; pii range[maxn]; int ind[maxn]; int opt[maxn]; struct Node { Node *l, *r; int v; Node() { l = r = NULL; v = 0; } } *version[maxn]; struct PersistentSegmentTree { void build(Node *node, int l, int r) { if (l == r) return; int mid = (l+r)>>1; node->l = new Node(); node->r = new Node(); build(node->l, l, mid); build(node->r, mid+1, r); } void upd(Node *prev, Node *node, int l, int r, int pos, int v) { if (l == r) { node->v = prev->v + v; return; } int mid = (l+r)>>1; if (pos <= mid) { if (!node->l) node->l = new Node(); node->r = prev->r; upd(prev->l, node->l, l, mid, pos, v); } else { if (!node->r) node->r = new Node(); node->l = prev->l; upd(prev->r, node->r, mid+1, r, pos, v); } node->v = node->l->v + node->r->v; } int query(Node *prev, Node *node, int l, int r, int a, int b) { if (l > b || r < a) return 0; if (l >= a && r <= b) return node->v - prev->v; int mid = (l+r)>>1; return query(prev->l, node->l, l, mid, a, b) + query(prev->r, node->r, mid+1, r, a, b); } int get(int l, int r, int k) { return query(version[ind[l]], version[ind[r]], 1, n, k, n); } } seg; void init(int N, int A[], int B[]) { n = N; for (int i = 1; i <= n; i++) range[i] = {A[i-1], B[i-1]}; sort(range+1, range+n+1); int ptr = 1, aux = 0; version[0] = new Node(); seg.build(version[0], 1, n); for (int i = 1; i <= n; i++) { while (ptr <= n && range[ptr].ff == i) { version[++aux] = new Node(); seg.upd(version[aux-1], version[aux], 1, n, range[ptr].ss, 1); ptr++; } ind[i] = aux; } } ll dp[maxn]; int fq[maxn]; void solve(vector<int> &V, int l, int r) { if (l > r) return; int mid = (l+r)>>1; int k = V[mid]; dp[mid] = 1ll*seg.get(0, k, k) - 1ll*fq[k]*k; for (int i = 0; i < mid; i++) dp[mid] = min(dp[mid], dp[i] + 1ll*seg.get(V[i], k, k) - 1ll*fq[k]*k); solve(V, l, mid-1); solve(V, mid+1, r); } int can(int M, int K[]) { int m = M; vector<int> V; for (int i = 0; i < m; i++) { V.push_back(K[i]); fq[K[i]]++; } sort(V.begin(), V.end()); V.erase(unique(V.begin(), V.end()), V.end()); m = V.size(); solve(V, 0, m-1); bool ok = 1; for (int j = 0; j < m; j++) { if (dp[j] < 0) ok = 0; dp[j] = fq[V[j]] = opt[j] = 0; } return ok; }

Compilation message (stderr)

teams.cpp: In function 'int can(int, int*)':
teams.cpp:148:12: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
  148 |  m = V.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...