Submission #44517181
Source Code Expand
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
using std::cout;
using std::cin;
using std::endl;
using ll=long long;
using ld=long double;
const ll ILL=2167167167167167167;
const int INF=2100000000;
const int mod=998244353;
#define rep(i,a,b) for (int i=(int)(a);i<(int)(b);i++)
#define all(p) p.begin(),p.end()
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});}
void yneos(bool a){if(a) cout<<"Yes\n"; else cout<<"No\n";}
template<class T> void vec_out(vector<T> &p){for(int i=0;i<(int)(p.size());i++){if(i) cout<<" ";cout<<p[i];}cout<<"\n";}
template<class T> T vec_min(vector<T> &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmin(ans,x);return ans;}
template<class T> T vec_max(vector<T> &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmax(ans,x);return ans;}
template<class T> T vec_sum(vector<T> &a){assert(!a.empty());T ans=a[0]-a[0];for(auto &x:a) ans+=x;return ans;}
int pop_count(long long a){int res=0;while(a){res+=(a&1),a>>=1;}return res;}
namespace atcoder {
namespace internal {
// @param n `0 <= n`
// @return minimum non-negative `x` s.t. `n <= 2**x`
int ceil_pow2(int n) {
int x = 0;
while ((1U << x) < (unsigned int)(n)) x++;
return x;
}
// @param n `1 <= n`
// @return minimum non-negative `x` s.t. `(n & (1 << x)) != 0`
int bsf(unsigned int n) {
#ifdef _MSC_VER
unsigned long index;
_BitScanForward(&index, n);
return index;
#else
return __builtin_ctz(n);
#endif
}
} // namespace internal
template <class S, S (*op)(S, S), S (*e)()> struct segtree {
public:
segtree() : segtree(0) {}
segtree(int n) : segtree(std::vector<S>(n, e())) {}
segtree(const std::vector<S>& v) : _n(int(v.size())) {
log = internal::ceil_pow2(_n);
size = 1 << log;
d = std::vector<S>(2 * size, e());
for (int i = 0; i < _n; i++) d[size + i] = v[i];
for (int i = size - 1; i >= 1; i--) {
update(i);
}
}
void set(int p, S x) {
assert(0 <= p && p < _n);
p += size;
d[p] = x;
for (int i = 1; i <= log; i++) update(p >> i);
}
S get(int p) {
assert(0 <= p && p < _n);
return d[p + size];
}
S prod(int l, int r) {
assert(0 <= l && l <= r && r <= _n);
S sml = e(), smr = e();
l += size;
r += size;
while (l < r) {
if (l & 1) sml = op(sml, d[l++]);
if (r & 1) smr = op(d[--r], smr);
l >>= 1;
r >>= 1;
}
return op(sml, smr);
}
S all_prod() { return d[1]; }
template <bool (*f)(S)> int max_right(int l) {
return max_right(l, [](S x) { return f(x); });
}
template <class F> int max_right(int l, F f) {
assert(0 <= l && l <= _n);
assert(f(e()));
if (l == _n) return _n;
l += size;
S sm = e();
do {
while (l % 2 == 0) l >>= 1;
if (!f(op(sm, d[l]))) {
while (l < size) {
l = (2 * l);
if (f(op(sm, d[l]))) {
sm = op(sm, d[l]);
l++;
}
}
return l - size;
}
sm = op(sm, d[l]);
l++;
} while ((l & -l) != l);
return _n;
}
template <bool (*f)(S)> int min_left(int r) {
return min_left(r, [](S x) { return f(x); });
}
template <class F> int min_left(int r, F f) {
assert(0 <= r && r <= _n);
assert(f(e()));
if (r == 0) return 0;
r += size;
S sm = e();
do {
r--;
while (r > 1 && (r % 2)) r >>= 1;
if (!f(op(d[r], sm))) {
while (r < size) {
r = (2 * r + 1);
if (f(op(d[r], sm))) {
sm = op(d[r], sm);
r--;
}
}
return r + 1 - size;
}
sm = op(d[r], sm);
} while ((r & -r) != r);
return 0;
}
private:
int _n, size, log;
std::vector<S> d;
void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); }
};
} // namespace atcoder
using namespace atcoder;
using F= pair<ll,ll>;
F op(F a,F b){return {a.first+b.first,a.second+b.second};}
F e(){return {0,0};}
ll target;
bool f(F a){
return target>a.first;
}
void solve();
// oddloop
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t=1;
//cin>>t;
rep(i,0,t) solve();
}
void solve(){
int N,M;
ll H;
cin>>N>>M>>H;
target=H;
vector<ll> A(N),B(N);
rep(i,0,N) cin>>A[i]>>B[i],B[i]--;
vector<ll> S(N);
vector<pair<ll,int>> p;
rep(i,0,M){
p.push_back({0,i});
}
rep(i,0,N){
S[B[i]]+=A[i];
p.push_back({S[B[i]],B[i]});
}
vector<vector<int>> G(M);
vector<int> ind(M);
So(p);
segtree<F,op,e> seg(N+M);
rep(i,0,N+M){
G[p[i].second].push_back(i);
}
rep(i,0,M) seg.set(i,{0,1});
vector<int> ans(M+1);
rep(i,0,M) S[i]=0;
rep(i,0,N){
seg.set(G[B[i]][ind[B[i]]],e());
ind[B[i]]++;
S[B[i]]+=A[i];
seg.set(G[B[i]][ind[B[i]]],{S[B[i]],1});
int b=seg.max_right<f>(0);
auto tmp=seg.prod(0,b);
ans[M-tmp.second]=i+1;
}
rep(i,0,M) chmax(ans[i+1],ans[i]);
vec_out(ans);
}
Submission Info
| Submission Time |
|
| Task |
G - Amulets |
| User |
potato167 |
| Language |
C++ 20 (gcc 12.2) |
| Score |
575 |
| Code Size |
6086 Byte |
| Status |
AC |
| Exec Time |
412 ms |
| Memory |
71032 KiB |
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
575 / 575 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
example0.txt, example1.txt |
| All |
000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, 037.txt, 038.txt, 039.txt, 040.txt, 041.txt, 042.txt, 043.txt, 044.txt, 045.txt, 046.txt, 047.txt, 048.txt, 049.txt, 050.txt, 051.txt, 052.txt, example0.txt, example1.txt |
| Case Name |
Status |
Exec Time |
Memory |
| 000.txt |
AC |
1 ms |
3416 KiB |
| 001.txt |
AC |
1 ms |
3520 KiB |
| 002.txt |
AC |
1 ms |
3516 KiB |
| 003.txt |
AC |
329 ms |
70876 KiB |
| 004.txt |
AC |
312 ms |
71032 KiB |
| 005.txt |
AC |
262 ms |
47524 KiB |
| 006.txt |
AC |
18 ms |
8336 KiB |
| 007.txt |
AC |
46 ms |
13284 KiB |
| 008.txt |
AC |
79 ms |
19408 KiB |
| 009.txt |
AC |
229 ms |
43772 KiB |
| 010.txt |
AC |
225 ms |
39196 KiB |
| 011.txt |
AC |
74 ms |
36148 KiB |
| 012.txt |
AC |
88 ms |
36096 KiB |
| 013.txt |
AC |
93 ms |
36196 KiB |
| 014.txt |
AC |
95 ms |
36200 KiB |
| 015.txt |
AC |
97 ms |
36252 KiB |
| 016.txt |
AC |
98 ms |
36020 KiB |
| 017.txt |
AC |
86 ms |
36104 KiB |
| 018.txt |
AC |
92 ms |
36108 KiB |
| 019.txt |
AC |
93 ms |
36100 KiB |
| 020.txt |
AC |
95 ms |
36084 KiB |
| 021.txt |
AC |
97 ms |
36148 KiB |
| 022.txt |
AC |
98 ms |
36084 KiB |
| 023.txt |
AC |
95 ms |
36016 KiB |
| 024.txt |
AC |
96 ms |
36180 KiB |
| 025.txt |
AC |
101 ms |
36088 KiB |
| 026.txt |
AC |
101 ms |
36184 KiB |
| 027.txt |
AC |
99 ms |
36024 KiB |
| 028.txt |
AC |
100 ms |
36184 KiB |
| 029.txt |
AC |
107 ms |
36080 KiB |
| 030.txt |
AC |
110 ms |
36112 KiB |
| 031.txt |
AC |
113 ms |
36084 KiB |
| 032.txt |
AC |
114 ms |
36108 KiB |
| 033.txt |
AC |
111 ms |
36092 KiB |
| 034.txt |
AC |
114 ms |
36192 KiB |
| 035.txt |
AC |
146 ms |
36384 KiB |
| 036.txt |
AC |
153 ms |
36280 KiB |
| 037.txt |
AC |
147 ms |
36424 KiB |
| 038.txt |
AC |
151 ms |
36416 KiB |
| 039.txt |
AC |
157 ms |
36524 KiB |
| 040.txt |
AC |
153 ms |
36364 KiB |
| 041.txt |
AC |
254 ms |
41796 KiB |
| 042.txt |
AC |
256 ms |
41748 KiB |
| 043.txt |
AC |
268 ms |
41804 KiB |
| 044.txt |
AC |
263 ms |
41696 KiB |
| 045.txt |
AC |
275 ms |
41628 KiB |
| 046.txt |
AC |
273 ms |
41652 KiB |
| 047.txt |
AC |
372 ms |
71020 KiB |
| 048.txt |
AC |
404 ms |
70880 KiB |
| 049.txt |
AC |
412 ms |
70928 KiB |
| 050.txt |
AC |
400 ms |
70972 KiB |
| 051.txt |
AC |
395 ms |
71016 KiB |
| 052.txt |
AC |
391 ms |
70976 KiB |
| example0.txt |
AC |
1 ms |
3440 KiB |
| example1.txt |
AC |
1 ms |
3376 KiB |