제출 #606474

#제출 시각아이디문제언어결과실행 시간메모리
6064748e7팀들 (IOI15_teams)C++17
0 / 100
493 ms203920 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]; 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]) seg[cur].push_back(ri[ind++]); seg[cur].push_back(le[i]); } while (ind < rs) seg[cur].push_back(ri[ind++]); } int query(int cur, int l, int r, int ql, int qr) { //number of segments covering [ql, qr] if (r <= l || l > ql) return 0; if (r-1 <= ql) { return seg[cur].end() - lower_bound(seg[cur].begin(), seg[cur].end(), qr); } int m = (l + r) / 2; return query(cur*2, l, m, ql, qr) + query(cur*2+1, m, r, ql, qr); } } tr; int v[maxn]; int n; void init(int N, int A[], int 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 } int can(int m, int num[]) { sort(num, num + m); vector<int> c(m, 0), dp(m, 0); int tot = 0; for (int i = 0;i < m;i++) { tot += v[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]); }; 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 */

컴파일 시 표준 에러 (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)':
teams.cpp:51:26: warning: conversion from '__gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type' {aka 'long int'} to 'int' may change value [-Wconversion]
   51 |    return seg[cur].end() - lower_bound(seg[cur].begin(), seg[cur].end(), qr);
      |           ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...