From 6bd2450f42a6cef004f1eda70b247376f6d00ddd Mon Sep 17 00:00:00 2001 From: Zengtudor Date: Mon, 12 Aug 2024 10:07:56 +0800 Subject: [PATCH] U88589 --- day10/U88589/U88589.cpp | 121 ++++++++++++++++++++++++++++++++++++++++ test.cpp | 11 +++- xmake.lua | 23 +++++--- 3 files changed, 147 insertions(+), 8 deletions(-) diff --git a/day10/U88589/U88589.cpp b/day10/U88589/U88589.cpp index e69de29..dc742ab 100644 --- a/day10/U88589/U88589.cpp +++ b/day10/U88589/U88589.cpp @@ -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 +using namespace std; +#define int long long + +const int MAX_X=1e5+5; +int q; +vectorv(MAX_X); +set s; +int getint(); + +signed main(signed argc,char *argv[]){ + #ifdef OITEST + cout<<"TESTING"<=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<>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; +} \ No newline at end of file diff --git a/test.cpp b/test.cpp index bafb007..40587ad 100644 --- a/test.cpp +++ b/test.cpp @@ -1,4 +1,13 @@ #include +using namespace std; + int main(){ - + sets; + s.insert(2); + s.insert(3); + auto it = s.lower_bound(2); + cout<<(*(--it))<