# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1088913 |
2024-09-15T13:56:35 Z |
yeediot |
Teams (IOI15_teams) |
C++17 |
|
470 ms |
292416 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 build(int l=1,int r=n){
int x=++cnt;
if(l==r){
return x;
}
int mid=(l+r)/2;
L[x]=build(l,mid);
R[x]=build(mid+1,r);
return x;
}
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]);
}
root[0] = build(1, n);
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> H(m);
vector<int> st;
st.push_back(0);
H[0]=n+1;
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];
int cur=vec[i];
while(!st.empty()){
int now=query(root[vec[i]],root[vec[st.back()]],H[i],H[st.back()]-1);
//cout<<now<<'\n';
if(now>=cur){
int below=query(root[vec[i]],root[vec[st.back()]],1,H[i]-1);
if(now==cur)H[i]=H[st.back()];
else H[i]=kth(root[vec[i]],root[vec[st.back()]],below+cur+1);
assert(H[i]<=H[st.back()]);
rem[i]=rem[st.back()]+query(root[vec[i]],root[vec[st.back()]],H[i],n);
break;
}
else{
H[i]=H[st.back()];
cur-=now;
st.pop_back();
}
}
if(H[st.back()]==H[i]) st.pop_back();
assert(H[i] <= H[st.back()]);
st.push_back(i);
}
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
119632 KB |
Output is correct |
2 |
Correct |
43 ms |
119792 KB |
Output is correct |
3 |
Correct |
47 ms |
119636 KB |
Output is correct |
4 |
Correct |
51 ms |
119764 KB |
Output is correct |
5 |
Correct |
47 ms |
119644 KB |
Output is correct |
6 |
Correct |
44 ms |
119888 KB |
Output is correct |
7 |
Correct |
43 ms |
119636 KB |
Output is correct |
8 |
Correct |
43 ms |
119632 KB |
Output is correct |
9 |
Incorrect |
43 ms |
119644 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
76 ms |
124500 KB |
Output is correct |
2 |
Correct |
79 ms |
124544 KB |
Output is correct |
3 |
Correct |
78 ms |
124724 KB |
Output is correct |
4 |
Correct |
83 ms |
124724 KB |
Output is correct |
5 |
Correct |
60 ms |
123472 KB |
Output is correct |
6 |
Correct |
63 ms |
123728 KB |
Output is correct |
7 |
Incorrect |
61 ms |
123472 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
83 ms |
124496 KB |
Output is correct |
2 |
Correct |
84 ms |
124500 KB |
Output is correct |
3 |
Correct |
186 ms |
124496 KB |
Output is correct |
4 |
Correct |
84 ms |
124496 KB |
Output is correct |
5 |
Correct |
92 ms |
123472 KB |
Output is correct |
6 |
Correct |
89 ms |
123476 KB |
Output is correct |
7 |
Incorrect |
93 ms |
123480 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
470 ms |
292416 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |