CppFastOlympicCoding 是什么?
https://celeste.dl.exlg.cc/latest/dist/extend-luogu.min.user.js
https://greasyfork.org/zh-CN/scripts/465777-codeforces-better
int l=0,r=n;
while(l+1<r){
int mid=l+r>>1;
if(check(mid)){
l=mid;
}else{
r=mid;
}
}
// l 符合的 -> max
// r 不符合的-> min// 从 C++11 开始,如果使用 lambda 函数自定义 Compare
// 则需要将其作为构造函数的参数代入,如:
auto cmp = [](const std::pair<int, int> &l, const std::pair<int, int> &r) {
return l.second < r.second;
};
std::priority_queue<std::pair<int, int>, std::vector<std::pair<int, int> >,decltype(cmp)> q(cmp);找max
while(l<r){
int mid=(l+r+1)>>1;
if(a[mid]<=x){
l=mid;
}else{
r=mid-1;
}
}
ans=a[l];
找min
while(l<r){
int mid=(l+r)>>1;
if(a[mid]>=x){
r=mid;
}else{
l=mid+1;
}
}
ans=a[l];
#include<bits/stdc++.h>
#define LL long long
#define endl '\n'
using namespace std;
const int maxint=2147483640;const LL maxll=9223372036854775800;
const unsigned LL maxull=1844674407370955160;
const int dx[4]={1, 0, -1, 0},dy[4]={0, 1, 0, -1};
inline int read(){int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-'){f=-1;}ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0',ch=getchar();}return x*f;}
void print(){}template <class T, class... Ts>
void print(const T& arg,const Ts&... args){cout<<arg;print(args...);}
const bool _fropen=false,_strem=false,_testcases=false;
/* ------------------------------------------------------------------------ */
const int maxn=100005;
void solve(){
}
int main(){
if(_fropen){
freopen(".in","r",stdin);
freopen(".out","w",stdout);
}
if(_strem){
std::ios::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
}
if(_testcases){
int T;cin>>T;
while(T-->0) solve();
}else solve();
return 0;
}线段树
#include<bits/stdc++.h>
#define LL long long
//#define ll long long
#define endl '\n'
#define mset(s,t) memset(s,t,sizeof(s))
#define len(x) (LL)(x).size()
#define lowbit(x) ((x)&(-(x)))
using namespace std;
const LL maxn=100005;
LL mod;
const LL maxint=2147483640;
const LL maxll=9223372036854775800;
const unsigned LL maxull=1844674407370955160;
const LL dx[4]={1, 0, -1, 0},dy[4]={0, 1, 0, -1};
const bool _fropen=false,_strem=false,_testcases=false;
#ifdef hmzclimc
#define debug(x...) cout<<" > line"<<__LINE__<<" : "<<#x<<" = ";err(x)
void err(){cout<<'\n';}template <class T, class... Ts>
void err(const T& arg,const Ts&... args){cout<<arg<<' ';err(args...);}
#endif
inline LL read(){LL x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-'){f=-1;}ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0',ch=getchar();}
return x*f;}
void print(){}template <class T, class... Ts>
void print(const T& arg,const Ts&... args){cout<<arg;print(args...);}
long long bigpow(long long a, long long b,long long mod){
long long res=1;while(b){if(b&1){
res=res*a%mod;}a=a*a%mod;b>>=1;}
return res;}
void initlog(LL lg[],LL n){
for(LL i=1;i<=n;i++){lg[i]=lg[i-1]+(1<<lg[i-1]==i);}}
/* ------------------------------------------------------------------------ */
LL n,m,arr[maxn];
LL t[maxn*4],lazya[maxn*4],lazyb[maxn*4],len[maxn*4];
LL ll[maxn*4],rr[maxn*4];
void upd(LL x,LL taga,LL tagb){
t[x]=(t[x]*tagb%mod+(len[x]*taga%mod)%mod)%mod;
lazya[x]=(lazya[x]*tagb%mod+taga)%mod;
lazyb[x]=(lazyb[x]*tagb)%mod;
}
void pushdown(LL x){
upd(x*2,lazya[x],lazyb[x]),upd(x*2+1,lazya[x],lazyb[x]);
lazya[x]=0,lazyb[x]=1;
}
LL sum(LL ql,LL qr,LL l,LL r,LL node){
//print(l,' ',r,'\n');
if(ql<=l&&r<=qr){
return t[node];
}
pushdown(node);
LL mid=(l+r)/2,ret=0;
if(ql<=mid){
ret=(ret+sum(ql,qr,l,mid,node*2))%mod;
}
if(mid<qr){
ret=(ret+sum(ql,qr,mid+1,r,node*2+1))%mod;
}
return ret;
}
void add(LL ql,LL qr,LL l,LL r,LL node,LL k,LL p){
if(ql<=l&&r<=qr){
upd(node,k,p);
return ;
}
pushdown(node);
LL mid=(l+r)/2;
if(ql<=mid){
add(ql,qr,l,mid,node*2,k,p);
}
if(mid<qr){
add(ql,qr,mid+1,r,node*2+1,k,p);
}
t[node]=(t[node*2]+t[node*2+1])%mod;
}
void build(LL l,LL r,LL node){
lazyb[node]=1;
ll[node]=l,rr[node]=r;
len[node]=r-l+1;
if(l==r){
t[node]=arr[l];
return ;
}
LL mid=(l+r)/2;
build(l,mid,node*2);
build(mid+1,r,node*2+1);
t[node]=(t[node*2]+t[node*2+1])%mod;
}
void init(){
n=read(),m=read(),mod=read();
for(LL i=1;i<=n;i++){
arr[i]=read();
}
}
void mainsolve(){
build(1,n,1);
while(m-->0){
LL op,x,y,k;
op=read(),x=read(),y=read();
if(op==1){
k=read();
add(x,y,1,n,1,0,k);
}else if(op==2){
k=read();
add(x,y,1,n,1,k,1);
}else{
print(sum(x,y,1,n,1));
puts("");
}
}
}
int main(){
if(_fropen){
freopen("","r",stdin);
freopen("","w",stdout);
}
if(_strem){
std::ios::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
}
if(_testcases){
LL T;
cin>>T;
while(T-->0){
init();
mainsolve();
}
}else{
init();
mainsolve();
}
return 0;
}