题面
维护一个\(n(n\leqslant 100000)\)个元素序列\(a_1,a_2,\dots,a_n\),有\(m(m\leqslant 100000)\)次操作,分为如下两种。
- 给定\(l,r,x\),将\(a_l,a_{l+1},\dots,a_r\)中所有大于\(x\)的元素减去\(x\)
- 给定\(l,r,x\),询问\(a_l,a_{l+1},\dots,a_r\)中,有多少个元素恰好等于\(x\)
思路
只要常数卡的好,暴力是珂以过的!
- 快速读入/快速输出
- 手动开
Ofast
代码
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
using namespace std;
namespace IO{
const int SIZE=1<<21;
static char ibuf[SIZE],obuf[SIZE],*iS,*iT,*oS=obuf,*oT=oS+SIZE-1;
int qr;
char qu[55],c;
bool f;
#define getchar() (IO::iS==IO::iT?(IO::iT=(IO::iS=IO::ibuf)+fread(IO::ibuf,1,IO::SIZE,stdin),(IO::iS==IO::iT?EOF:*IO::iS++)):*IO::iS++)
#define putchar(x) (*IO::oS++=x,IO::oS==IO::oT?flush():0)
#define flush() (fwrite(IO::obuf,1,IO::oS-IO::obuf,stdout),IO::oS=IO::obuf)
template<typename T>
inline bool read(T&x){
for(f=1,c=getchar();c<48||c>57;c=getchar()){
f^=c=='-';if(!~c) return false;
}
for(x=0;c<=57&&c>=48;c=getchar())
x=(x<<1)+(x<<3)+(c&15);
x=f?x:-x;
return true;
}
inline void outstr(const char*s){
for(int i=0;s[i];++i)
putchar(s[i]);
}
inline void outstr(const string&s){
for(size_t i=0;i<s.length();++i)
putchar(s[i]);
}
template<typename T>
inline void write(T x){
if(!x) putchar(48);
else{
if(x<0) putchar('-'),x=-x;
while(x) qu[++qr]=x%10^48,x/=10;
while(qr) putchar(qu[qr--]);
}
}
template<typename T>
inline void write(T x,const char*s){
if(!x) putchar(48);
else{
if(x<0) putchar('-'),x=-x;
while(x) qu[++qr]=x%10^48,x/=10;
while(qr) putchar(qu[qr--]);
}
outstr(s);
}
struct Flusher_{~Flusher_(){flush();}}io_flusher_;
}
using IO::read;
using IO::write;
using IO::outstr;
int a[100005];
int main(){
int n,m,op,l,r,x,ans;
read(n),read(m);
for(int i=1;i<=n;++i){
read(a[i]);
}
while(m--){
read(op),read(l),read(r),read(x);
if(op==1){
for(int i=l;i<=r;++i){
a[i]=(a[i]>x)?(a[i]-x):a[i];
}
}
else{
ans=0;
for(int i=l;i<=r;++i)
ans+=(a[i]==x);
write(ans,"\n");
}
}
return 0;
}
标签:dots,Chtholly,48,Welcome,else,inline,home,getchar
From: https://www.cnblogs.com/zheyuanxie/p/cf896e.html