# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
990612 |
2024-05-30T17:20:27 Z |
User0069 |
Teams (IOI15_teams) |
C++17 |
|
1091 ms |
384400 KB |
#include<bits/stdc++.h>
#include"teams.h"
#define taskname ""
#define el '\n'
#define fi first
#define sc second
#define pii pair<int, int>
#define all(v) v.begin(), v.end()
#define int ll
using namespace std;
using ll=long long;
using ull=unsigned long long;
using ld=long double;
#define Faster ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
const int maxn=5e5+3;
const int mod=1e9+7;
const int INF=1e9+7;
int N;
struct node
{
node *l,*r;
int val;
node():l(NULL),r(NULL),val(0){};
};
node* root[maxn];
vector<int> v[maxn];
node* cons(node* kk,int cl,int cr)
{
kk=new node();
if(cl==cr)
{
return kk;
}
int mid=(cl+cr)/2;
kk->l=cons(kk->l,cl,mid);
kk->r=cons(kk->r,mid+1,cr);
return kk;
}
node* update(node* kk,int cl,int cr,int pos,int val)
{
node* kkk=new node();
kkk->l=kk->l;
kkk->r=kk->r;
kkk->val=kk->val;
if(cl==cr)
{
kkk->val+=val;
return kkk;
}
int mid=(cl+cr)/2;
if(pos<=mid) kkk->l=update(kk->l,cl,mid,pos,val);
else kkk->r=update(kk->r,mid+1,cr,pos,val);
kkk->val=kkk->l->val+kkk->r->val;
return kkk;
}
int get(node* kk,int cl,int cr,int l,int r )
{
if(cl>r||cr<l) return 0;
if(cl>=l&&cr<=r) return kk->val;
int mid=(cl+cr)/2;
return get(kk->l,cl,mid,l,r)+get(kk->r,mid+1,cr,l,r);
}
int cnt(int a,int b,int c,int d)
{
return get(root[b],0,N,c,d)-get(root[a-1],0,N,c,d);
}
void init(int32_t n,int32_t* a,int32_t* b)
{
N=n;
root[0]=cons(root[0],0,n);
for(int i=0;i<n;i++)
{
v[b[i]].push_back(a[i]);
}
for(int i=1;i<=n;i++)
{
root[i]=root[i-1];
for(int x:v[i])
{
root[i]=update(root[i],0,n,x,1);
}
}
root[n+1]=root[n];
}
int32_t can(int32_t m,int32_t* k)
{
int sum=0;
int need=0;
int borrow=0,prev,late;
sort(k,k+m);
for(int i=0;i<m;i++)
{
need+=k[i];
if(i==0) prev=0;
else prev=k[i-1];
if(i==m-1) late=N+1;
else late=k[i+1];
sum+=cnt(k[i],late-1,prev+1,k[i]);
if(sum>need) sum=need;
sum+=cnt(late,N,prev+1,k[i]);
if(sum<need) return 0;
}
return 1;
}
//signed main()
//{
// if (fopen(taskname".INP","r"))
// {
// freopen(taskname".INP","r",stdin);
// freopen(taskname".OUT","w",stdout);
// }
// Faster
//}
Compilation message
teams.cpp: In function 'int32_t can(int32_t, int32_t*)':
teams.cpp:90:9: warning: unused variable 'borrow' [-Wunused-variable]
90 | int borrow=0,prev,late;
| ^~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12888 KB |
Output is correct |
2 |
Correct |
2 ms |
12892 KB |
Output is correct |
3 |
Correct |
2 ms |
12892 KB |
Output is correct |
4 |
Correct |
2 ms |
12892 KB |
Output is correct |
5 |
Correct |
2 ms |
12892 KB |
Output is correct |
6 |
Correct |
2 ms |
12892 KB |
Output is correct |
7 |
Correct |
2 ms |
12892 KB |
Output is correct |
8 |
Correct |
2 ms |
12892 KB |
Output is correct |
9 |
Correct |
2 ms |
12892 KB |
Output is correct |
10 |
Correct |
2 ms |
12888 KB |
Output is correct |
11 |
Incorrect |
3 ms |
12888 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
96 ms |
79188 KB |
Output is correct |
2 |
Correct |
94 ms |
79188 KB |
Output is correct |
3 |
Correct |
94 ms |
79184 KB |
Output is correct |
4 |
Correct |
93 ms |
79576 KB |
Output is correct |
5 |
Correct |
63 ms |
78420 KB |
Output is correct |
6 |
Correct |
66 ms |
78420 KB |
Output is correct |
7 |
Correct |
62 ms |
78420 KB |
Output is correct |
8 |
Correct |
61 ms |
79096 KB |
Output is correct |
9 |
Incorrect |
62 ms |
80072 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
104 ms |
79692 KB |
Output is correct |
2 |
Correct |
97 ms |
79696 KB |
Output is correct |
3 |
Correct |
232 ms |
82516 KB |
Output is correct |
4 |
Correct |
97 ms |
79692 KB |
Output is correct |
5 |
Correct |
101 ms |
78840 KB |
Output is correct |
6 |
Correct |
97 ms |
78760 KB |
Output is correct |
7 |
Correct |
67 ms |
78932 KB |
Output is correct |
8 |
Correct |
88 ms |
79956 KB |
Output is correct |
9 |
Incorrect |
64 ms |
80064 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
631 ms |
374608 KB |
Output is correct |
2 |
Correct |
647 ms |
378112 KB |
Output is correct |
3 |
Correct |
1091 ms |
384400 KB |
Output is correct |
4 |
Correct |
634 ms |
378136 KB |
Output is correct |
5 |
Correct |
442 ms |
372560 KB |
Output is correct |
6 |
Correct |
461 ms |
372304 KB |
Output is correct |
7 |
Correct |
394 ms |
372480 KB |
Output is correct |
8 |
Correct |
411 ms |
374360 KB |
Output is correct |
9 |
Incorrect |
336 ms |
373692 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |