# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1088917 |
2024-09-15T14:17:47 Z |
guagua0407 |
Teams (IOI15_teams) |
C++17 |
|
751 ms |
151376 KB |
#include "teams.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int mxn=5e5+5;
const int inf=1e9;
vector<int> segtree(mxn*20);
vector<int> R(mxn*20),L(mxn*20);
vector<int> root(mxn);
int n;
int cnt=0;
int update(int node,int pos,int l=1,int r=n){
int x=++cnt;
assert(x<mxn*20);
L[x]=L[node];
R[x]=R[node];
segtree[x]=segtree[node];
if(l==r){
segtree[x]++;
return x;
}
int mid=(l+r)/2;
if(pos<=mid) L[x]=update(L[node],pos,l,mid);
else R[x]=update(R[node],pos,mid+1,r);
segtree[x]=segtree[L[x]]+segtree[R[x]];
return x;
}
int query(int node1,int node2,int tl,int tr,int l=1,int r=n){
if(r<tl or tr<l){
return 0;
}
if(tl<=l and r<=tr){
return segtree[node1]-segtree[node2];
}
int mid=(l+r)/2;
return query(L[node1],L[node2],tl,min(mid,tr),l,mid)+query(R[node1],R[node2],max(mid+1,tl),tr,mid+1,r);
}
int kth(int node1,int node2,int k,int l=1,int r=n){
if(l==r){
return l;
}
int sum=segtree[L[node1]]-segtree[L[node2]];
int mid=(l+r)/2;
if(k<=sum) return kth(L[node1],L[node2],k,l,mid);
else return kth(R[node1],R[node2],k-sum,mid+1,r);
}
void init(int N, int A[], int B[]) {
n=N;
vector<vector<int>> vec(n+1);
for(int i=0;i<n;i++){
vec[A[i]].push_back(B[i]);
}
for(int i=1;i<=n;i++){
root[i]=root[i-1];
for(auto v:vec[i]){
root[i]=update(root[i],v);
}
}
}
int can(int M, int K[]) {
sort(K,K+M);
int m=M+1;
vector<int> vec(m);
for(int i=1;i<m;i++){
vec[i]=K[i-1];
}
vector<int> rem(m);
vector<int> used(m);
vector<int> H(m);
vector<int> st;
st.push_back(0);
H[0]=n+1;
//cout<<'\n';
for(int i=1;i<m;i++){
while(!st.empty() and H[st.back()]<=vec[i]){
st.pop_back();
}
int sum=rem[st.back()]+query(root[vec[i]],root[vec[st.back()]],vec[i],n);
//cout<<sum<<' '<<rem[st.back()]<<' '<<query(root[vec[i]],root[vec[st.back()]],vec[i],n)<<'\n';
if(sum<vec[i]){
return 0;
}
H[i]=vec[i];
used[i]=query(root[vec[i]],root[vec[st.back()]],1,H[i]-1);
int cur=vec[i];
while(!st.empty()){
int now=query(root[vec[i]],root[vec[st.back()]],1,H[st.back()]-1)-used[i];
//cout<<now<<'\n';
if(now>=cur){
used[i]+=cur;
if(now==cur) H[i]=H[st.back()];
else H[i]=kth(root[vec[i]],root[vec[st.back()]],used[i]+1);
assert(H[i]<=H[st.back()]);
rem[i]=rem[st.back()]+query(root[vec[i]],root[vec[st.back()]],1,n)-used[i];
break;
}
else{
H[i]=H[st.back()];
used[i]+=used[st.back()];
used[i]+=now;
cur-=now;
st.pop_back();
}
}
if(H[st.back()]==H[i]) st.pop_back();
st.push_back(i);
}
return 1;
}
/*int main() {
int N;
cin>>N;
int *A = (int*)malloc(sizeof(int)*(unsigned int)N);
int *B = (int*)malloc(sizeof(int)*(unsigned int)N);
for (int i = 0; i < N; ++i) {
cin>>A[i]>>B[i];
}
init(N, A, B);
int Q;
cin>>Q;
for (int i = 0; i < Q; ++i) {
int M;
cin>>M;
int *K = (int*)malloc(sizeof(int)*(unsigned int)M);
for (int j = 0; j < M; ++j) {
cin>>K[j];
}
cout<<can(M, K)<<'\n';
}
return 0;
}*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
119632 KB |
Output is correct |
2 |
Correct |
46 ms |
119636 KB |
Output is correct |
3 |
Correct |
47 ms |
119632 KB |
Output is correct |
4 |
Correct |
44 ms |
119636 KB |
Output is correct |
5 |
Correct |
42 ms |
119648 KB |
Output is correct |
6 |
Correct |
45 ms |
119844 KB |
Output is correct |
7 |
Correct |
46 ms |
119636 KB |
Output is correct |
8 |
Correct |
49 ms |
119632 KB |
Output is correct |
9 |
Incorrect |
46 ms |
119600 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
80 ms |
125780 KB |
Output is correct |
2 |
Correct |
86 ms |
125880 KB |
Output is correct |
3 |
Correct |
91 ms |
125708 KB |
Output is correct |
4 |
Correct |
85 ms |
126032 KB |
Output is correct |
5 |
Correct |
63 ms |
124244 KB |
Output is correct |
6 |
Correct |
64 ms |
124264 KB |
Output is correct |
7 |
Incorrect |
75 ms |
124236 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
85 ms |
126032 KB |
Output is correct |
2 |
Correct |
86 ms |
126076 KB |
Output is correct |
3 |
Correct |
158 ms |
126032 KB |
Output is correct |
4 |
Correct |
83 ms |
126036 KB |
Output is correct |
5 |
Correct |
85 ms |
124492 KB |
Output is correct |
6 |
Correct |
82 ms |
124500 KB |
Output is correct |
7 |
Incorrect |
83 ms |
124500 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
355 ms |
151124 KB |
Output is correct |
2 |
Correct |
349 ms |
151124 KB |
Output is correct |
3 |
Correct |
751 ms |
151376 KB |
Output is correct |
4 |
Correct |
365 ms |
151208 KB |
Output is correct |
5 |
Correct |
200 ms |
142556 KB |
Output is correct |
6 |
Correct |
191 ms |
142408 KB |
Output is correct |
7 |
Incorrect |
198 ms |
142416 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |