Submission #384585

#TimeUsernameProblemLanguageResultExecution timeMemory
384585luciocfTeams (IOI15_teams)C++14
0 / 100
4101 ms358072 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]; vector<int> V; void solve(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; opt[mid] = mid; for (int i = 0; i < mid; i++) { ll x = dp[i] + 1ll*seg.get(V[i], k, k) - 1ll*fq[k]*k; if (x < dp[mid]) dp[mid] = x, opt[mid] = i; } solve(l, mid-1); solve(mid+1, r); } int can(int M, int K[]) { int m = M; V.clear(); 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(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:155:12: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
  155 |  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...