QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#399770 | #6754. Selection | ericmegalovania# | AC ✓ | 1ms | 4184kb | C++20 | 4.2kb | 2024-04-26 17:44:31 | 2024-04-26 17:44:31 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ONLINE
#ifndef ONLINE
#define debug(...) fprintf(stderr,##__VA_ARGS__)
#else
#define debug(...) ;
#endif
using LL=long long;
using PII=pair<int,int>;
#define N 1010
int a[N],b[N];//a:val b:gender
template<typename T>
inline T READ(){
T x=0; bool f=0; char c=getchar();
while(c<'0' || c>'9') f|=(c=='-'),c=getchar();
while(c>='0' && c<='9') x=x*10+c-'0',c=getchar();
return f?-x:x;
}
inline int read(){return READ<int>();}
inline LL readLL(){return READ<LL>();}
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
template<typename T>
class fhqTreap{
private:
struct Node{
int l,r,siz; LL rnd;
T val,sum;
Node(){
l=r=siz=0; rnd=0ll;
val=sum=T(0);
}
Node(int l_,int r_,int siz_,LL rnd_,T val_,T sum_){
l=l_,r=r_,siz=siz_; rnd=rnd_;
val=val_,sum=sum_;
}
};
vector<Node>q;
int root,rootX,rootY,rootZ;
int New(T val){
Node new_node=Node(0,0,1,rng(),val,val);
q.push_back(new_node);
return q.size()-1;
}
void Update(int id){
q[id].siz=q[q[id].l].siz+q[q[id].r].siz+1;
q[id].sum=q[q[id].l].val+q[q[id].r].val+q[id].val;
}
void Split(int id,T key,int& idX,int& idY){
if(id==0){
idX=idY=0;
return;
}
if(q[id].val<=key){
idX=id;
Split(q[id].r,key,q[id].r,idY);
}
else{
idY=id;
Split(q[id].l,key,idX,q[id].l);
}
Update(id);
}
int Merge(int l,int r){
if(l==0 || r==0) return l+r;
if(q[l].rnd<=q[r].rnd){
q[r].l=Merge(l,q[r].l);
Update(r);
return r;
}
else{
q[l].r=Merge(q[l].r,r);
Update(l);
return l;
}
}
public:
fhqTreap(){
init();
}
void init(){
root=0; q.clear();
Node empty_node=Node();
q.push_back(empty_node);
}
void insert(T val){
Split(root,val,rootX,rootY);
root=Merge(Merge(rootX,New(val)),rootY);
}
void erase(T val){//actually, 'extract' may be more precise
Split(root,val,rootX,rootZ);
Split(rootX,val-1,rootX,rootY);
rootY=Merge(q[rootY].l,q[rootY].r);
root=Merge(Merge(rootX,rootY),rootZ);
}
T prev(T val){
Split(root,val-1,rootX,rootY);
int tmp=rootX;
while(q[tmp].r) tmp=q[tmp].r;
root=Merge(rootX,rootY);
return q[tmp].val;
}
T next(T val){
Split(root,val,rootX,rootY);
int tmp=rootY;
while(q[tmp].l) tmp=q[tmp].l;
root=Merge(rootX,rootY);
return q[tmp].val;
}
int rank(T val){//val's rank
Split(root,val-1,rootX,rootY);
int ans=q[rootX].siz+1;
root=Merge(rootX,rootY);
return ans;
}
T get(int rank){
int id=root;
while(1){
// printf("id:%d val:%d l:%d lsiz:%d r:%d rsiz:%d|rank:%d\n",id,q[id].val,q[id].l,q[q[id].l].siz,q[id].r,q[q[id].r].siz,rank);
if(q[q[id].l].siz>=rank) id=q[id].l;
else if(q[q[id].l].siz+1==rank) return q[id].val;
else{
rank-=(q[q[id].l].siz+1);
id=q[id].r;
}
}
}
// void output(){
// auto dfs=[&](auto self,int u)->void{
// if(!u) return;
// self(self,q[u].l);
// debug("%d|val=%d ls=%d rs=%d\n",u,q[u].val,q[u].l,q[u].r);
// self(self,q[u].r);
// };
// debug("output fhqTreap\n");
// dfs(dfs,root);
// debug("\n");
// }
};
int main(){
int n=read(),m=read(),T=read();
fhqTreap<LL>all;
set<int>girl;
for(int i=1;i<=n;i++){
a[i]=read(),b[i]=read();
all.insert(a[i]);
if(b[i]) girl.insert(a[i]);
}
for(int op,id,x,ans;T--;){
op=read(),id=read();
if(op==1){
x=read();
if(b[id]==x) continue;
if(b[id]) girl.erase(a[id]);
else girl.insert(a[id]);
b[id]=x;
}
else{
if(!b[id]){
if(girl.size()){
x=*girl.rbegin();
all.erase(x);
ans=(n-all.rank(a[id])<=m-1);
all.insert(x);
}
else{
debug("rank(%d)=%d\n",a[id],all.rank(a[id]));
ans=(n+1-all.rank(a[id])<=m);
}
}
else{
x=*girl.rbegin();
if(a[id]==x){
ans=1;
}
else{
all.erase(x);
ans=(n-all.rank(a[id])<=m-1);
all.insert(x);
}
}
debug("girl.size()=%d\n",girl.size());
printf("%d\n",ans);
}
}
return 0;
}
/* stuff you should look for
* int overflow, array bounds
* special cases (n=1?)
* do smth instead of nothing and stay organized
* WRITE STUFF DOWN
* DON'T GET STUCK ON ONE APPROACH
*/
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 4048kb
input:
3 2 3 3 0 1 1 2 0 2 2 1 2 0 2 2
output:
1 0
result:
ok 2 number(s): "1 0"
Test #2:
score: 0
Accepted
time: 1ms
memory: 4184kb
input:
1000 1 1000 617 0 199 0 776 0 536 1 258 0 311 1 579 0 844 0 356 1 587 0 564 0 782 0 37 1 717 1 612 1 245 1 444 1 750 0 52 1 92 1 741 0 266 1 71 1 189 1 419 1 580 1 585 1 268 1 255 0 490 1 70 1 497 1 829 1 469 1 641 0 929 1 379 1 507 0 474 1 407 0 221 1 985 0 815 1 217 0 445 1 386 0 132 0 154 0 736 1...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 470 numbers
Test #3:
score: 0
Accepted
time: 0ms
memory: 3900kb
input:
1000 1 1000 541 1 236 1 583 1 99 0 324 0 107 0 459 0 854 0 772 0 426 1 717 1 806 0 335 0 503 0 860 0 463 1 306 1 813 0 947 1 989 0 736 1 713 0 65 1 222 0 428 0 680 0 652 1 681 1 661 0 595 1 474 1 70 1 641 1 688 0 591 0 20 1 330 1 563 0 38 1 638 1 391 1 979 1 488 0 829 0 956 1 395 1 694 0 669 0 567 0...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 516 numbers
Test #4:
score: 0
Accepted
time: 1ms
memory: 3936kb
input:
1000 50 1000 950 0 163 0 276 0 422 1 449 0 81 0 245 1 995 1 908 1 466 0 123 0 848 1 749 0 370 1 86 1 299 1 384 0 570 1 678 0 713 0 360 0 737 0 627 0 60 1 250 1 88 1 915 1 145 0 863 0 925 1 742 0 409 1 858 1 441 0 803 0 811 1 575 0 47 0 271 1 107 1 431 0 677 1 704 0 340 0 160 0 856 1 176 0 488 1 832 ...
output:
0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 ...
result:
ok 511 numbers
Test #5:
score: 0
Accepted
time: 0ms
memory: 3892kb
input:
1000 1 1000 900 1 127 1 89 1 836 1 434 1 912 1 459 0 155 1 394 0 669 1 33 1 584 0 80 0 433 1 284 1 43 0 377 0 84 1 91 1 158 0 406 1 654 0 604 0 469 1 352 1 762 1 824 0 423 1 172 0 62 1 399 0 130 1 19 1 640 1 212 0 215 0 661 0 597 0 309 1 688 1 978 0 677 0 170 0 853 1 448 1 945 1 765 0 751 0 830 0 25...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 467 numbers
Test #6:
score: 0
Accepted
time: 1ms
memory: 3964kb
input:
1000 10 1000 135 1 844 1 342 0 548 0 385 0 595 1 271 1 189 0 685 0 951 0 586 0 132 0 537 0 99 1 828 1 676 1 407 1 20 0 297 0 91 1 336 1 113 0 370 1 498 0 201 1 866 1 64 0 443 0 852 0 46 0 51 0 146 1 650 1 60 0 349 0 773 1 556 0 219 1 526 1 659 1 913 1 260 1 186 0 787 0 130 1 669 0 307 1 105 1 316 1 ...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 488 numbers