This commit is contained in:
Zengtudor 2024-08-12 10:07:56 +08:00
parent c9cd8df58a
commit 6bd2450f42
3 changed files with 147 additions and 8 deletions

View File

@ -0,0 +1,121 @@
/*
[set容器]
- `1 x`: $x$
- `2 x`: $x$ $1$
- `3 l r`: $l\le x\le r$ $x$ []
- `4 x`: <= x `-1`
- `5 x`: >= x `-1`
1 2
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MAX_X=1e5+5;
int q;
vector<int>v(MAX_X);
set<int> s;
int getint();
signed main(signed argc,char *argv[]){
#ifdef OITEST
cout<<"TESTING"<<endl;
#define AS(c){if(!(c)){cerr<<"assert failed:"<<#c<<endl;return -1;}}
#define ASM(a,b){if((a)!=(b)){cerr<<"assert failed: "<<a<<endl<<b<<endl;return 1;}}
AS(argc==3)
auto fin = freopen(argv[1],"r",stdin);
AS(fin!=NULL)
ifstream afile(argv[2]);
stringstream ss;
#define cout ss
int ans_num = 0;
#endif
q=getint();
for(int i=1;i<=q;i++){
const int n=getint();
#ifdef OITEST
if(n>=3){
ans_num++;
}
#endif
if(n==1){
const int x=getint();
/*auto state = */s.insert(x);
if(x>=v.size())v.resize(x+1);
v[x]++;
}else if (n==2) {
const int x=getint();
v[x]--;
if(v[x]==0){s.erase(x);}
}else if(n==3){
const int l=getint(),r=getint();
const auto sl=s.lower_bound(l)
,sr=s.lower_bound(r);
int ans=0;
for(auto i=sl;i!=sr;i++){
ans+=(*i)*v[(*i)];
}
if ((*sr)==r) {
ans+=(*sr)*v[(*sr)];
}
cout<<ans<<endl;
}else if(n==4){
const int x=getint();
// if(x==99){
// cerr<<"debugging"<<endl;
// }
auto it=s.lower_bound(x);
if((*it)==x){
cout<<x<<endl;
continue;
}else{
it--;
if((*it)<x){
cout<<(*it)<<endl;
continue;
}else{
cout<<-1<<endl;
continue;
}
}
cout<<(*it)<<endl;
}else if(n==5){
const int x=getint();
auto it=s.lower_bound(x);
if(it==s.end()){
cout<<-1<<endl;
continue;
}
cout<<(*it)<<endl;
}
}
#ifdef OITEST
for(int i=1;i<=ans_num;i++){
int cans ,myans;
afile>>cans;
ss>>myans;
ASM(cans,myans)
}
#endif
}
int getint(){
int x=0,w=1;
char ch=0;
while(!isdigit(ch)){
if(ch=='-')w=-1;
ch=getchar();
}
while(isdigit(ch)){
x=x*10+(ch-'0');
ch=getchar();
}
return x*w;
}

View File

@ -1,4 +1,13 @@
#include<bits/stdc++.h>
using namespace std;
int main(){
set<int>s;
s.insert(2);
s.insert(3);
auto it = s.lower_bound(2);
cout<<(*(--it))<<endl;
cout<<(*(++it))<<endl;
cout<<(*(--it))<<endl;
cout<<(*(--it))<<endl;
}

View File

@ -89,10 +89,19 @@ target("U279656")
add_tests(s,{files="./day8/U279656/*.cpp",runargs={"seg"..s..".in","seg"..s..".ans"},defines="OITEST",run_timeout=1000})
end
target("P2580")
set_rundir("./day9/P2580")
add_files("./day9/P2580/*.cpp")
for v=1,2 do
local s=tostring(v)
add_tests(s,{files="./day9/P2580/*.cpp",runargs={"P2580_"..s..".in","P2580_"..s..".out"},defines="OITEST",run_timeout=1000})
end
target("P2580")
set_rundir("./day9/P2580")
add_files("./day9/P2580/*.cpp")
for v=1,2 do
local s=tostring(v)
add_tests(s,{files="./day9/P2580/*.cpp",runargs={"P2580_"..s..".in","P2580_"..s..".out"},defines="OITEST",run_timeout=1000})
end
target("U88589")
set_rundir("./day10/U88589")
add_files("./day10/U88589/*.cpp")
-- add_defines("OITEST")
for v=1,2 do
local s=tostring(v)
add_tests(s,{files="./day10/U88589/*.cpp",runargs={s..".in",s..".ans"},defines="OITEST",run_timeout=1000})
end