C++#include<bits/stdc++.h>
using namespace std;
int n,w,a[100005];
int lowbit(int a){
return a&-a;
}
void add(int p,int x){
while(p<=n){
a[p]+=x;
p+=lowbit(p);
}
}
int ask(int p){
int ans=0;
while(p>0){
ans+=a[p];
p-=lowbit(p);
}
return ans;
}
int main(){
cin>>n>>w;
for(register int i=1;i<=w;i++){
char q;
int y,z;
cin>>q>>y>>z;
if(q=='x')add(y,z);
else cout<<ask(z)-ask(y-1)<<endl;
}
return 0;
}
C++#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int n,m,i,j,mid,l,r;
int p[1000001],d[1000001],s[1000001],t[1000001],alpha[1000001];
bool check(int there){
memset(alpha,0,sizeof(alpha));
for(int i=1; i <= there; i++)
{
alpha[s[i]] += d[i];
alpha[t[i]+1] -= d[i];
}
register int all=0;
for(int i=1; i <= n; i++)
{
all += alpha[i];
if(all>p[i]) return false;
}
return true;
}
int main()
{
ios::sync_with_stdio(false);
cin>>n>>m;
for(int i=1; i <= n; i++)
cin>>p[i];
for(int i=1; i <= m; i++)
cin>>d[i]>>s[i]>>t[i];
l=0;
r=m+1;
mid=(l+r)/2;
while(l+1 < r){
if(check(mid)) l=mid;
else r=mid;
mid=(l+r)/2;
}
if(l == m) cout<<"0";
else{
cout<<"-1"<<endl;
cout<<l+1<<endl;
}
return (0^0);
}
C++#include<bits/stdc++.h>
using namespace std;
char a[1000005],b[1000005];
int p[1000005];
int main() {
cin>>a+1;
cin>>b+1;
int lena=strlen(a+1),lenb=strlen(b+1);
int j=0;
p[1]=0;
for(register int i=2; i<=lenb; i++) {
while(j>0&&b[i]!=b[j+1])j=p[j];
if(b[i]==b[j+1])j++;
p[i]=j;
}
j=0;
for(register int i=1; i<=lena; i++) {
while(j>0&&a[i]!=b[j+1])j=p[j];
if(a[i]==b[j+1])j++;
if(j==lenb)cout<<(i-lenb+1)<<endl,j=p[j];
}
for(register int i=1; i<lenb; i++)
cout<<p[i]<<" ";
cout<<p[lenb];
return 0;
}
f(x)=⎩⎨⎧22nΓ(2n)1x2n−1e−2x,x>0;0,x≤0
Γ(x)=∫0+∞tx−1e−tdt
∫abf(x)dx≈6(b−a)(f(a)+f(b)+4f(2a+b)
xσ=∑i=1nmi∑i=1nximi
yσ=∑i=1nmi∑i=1nyimi