比赛链接https://www.luogu.com.cn/contest/126344
[APC001] A - CT
不必多说,多次取模
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<queue>
#include<deque>
#include<math.h>
#include<map>
#include<stack>
#include<set>
#include<vector>
#include<random>
using namespace std;
typedef long long ll;
const ll mod= 988444333;
void fio()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
ll ksm(ll x,ll y)
{
ll ans=1;
while(y)
{
if(y&1)
ans*=x;
x*=x;
y>>=1;
}
return ans;
}
ll gcd(ll x,ll y)
{
if(y==0)
return x;
else
return gcd(y,x%y);
}
int main()
{
fio();
ll a,b,h,k;
cin>>a>>b>>h>>k;
cout<<(a+k)*(b+k)%mod*(h+k)%mod%mod<<endl;
}
[APC001] B - Checker
隐性条件,每个题目中的字符串长度和小k的字符串长度一样,暴力枚举
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<queue>
#include<deque>
#include<math.h>
#include<map>
#include<stack>
#include<set>
#include<vector>
#include<random>
using namespace std;
typedef long long ll;
const ll mod= 988444333;
void fio()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
ll ksm(ll x,ll y)
{
ll ans=1;
while(y)
{
if(y&1)
ans*=x;
x*=x;
y>>=1;
}
return ans;
}
ll gcd(ll x,ll y)
{
if(y==0)
return x;
else
return gcd(y,x%y);
}
int main()
{
fio();
ll n;
cin>>n;
string f;
cin>>f;
ll cnt=0;
while(n--)
{
string x;
cin>>x;
ll ans=0;
for(ll i=0;i<x.size();i++)
{
if(f[i]==x[i])
ans++;
}
if(ans>=(x.size()+1)/2)cnt++;
}
cout<<cnt<<endl;
if(cnt==0)
cout<<"Good job!"<<endl;
else
cout<<"Make persistent efforts."<<endl;
}
[APC001] C - Not APC
求字符串能删除多少个子序列APC。
用两个stack维护即可,遇到一个A就用一个栈记住,遇到一个P就查询存a的栈,然后再考虑对AP栈操作。
随后遇到c,只考虑AP栈有无即可
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<queue>
#include<deque>
#include<math.h>
#include<map>
#include<stack>
#include<set>
#include<vector>
#include<random>
using namespace std;
typedef long long ll;
const ll mod= 988444333;
void fio()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
ll ksm(ll x,ll y)
{
ll ans=1;
while(y)
{
if(y&1)
ans*=x;
x*=x;
y>>=1;
}
return ans;
}
ll gcd(ll x,ll y)
{
if(y==0)
return x;
else
return gcd(y,x%y);
}
pair<ll,pair<ll,ll>>ans[1000052];
bool cd[1000005];
int main()
{
fio();
ll t;
cin>>t;
ll cnt=0;
while(t--)
{
cnt=0;
string f;
cin>>f;
stack<ll>a;
stack<pair<ll,ll>>ab;
for(ll i=0;i<f.size();i++)
{
if(f[i]=='A')
{
a.push(i);
}
else if(f[i]=='P')
{
if(!a.empty())
{
ab.push({a.top(),i});
a.pop();
}
}
else
{
if(!ab.empty())
{
cnt++;
ans[cnt]={ab.top().first,{ab.top().second,i}};
cd[ab.top().first]=1;
cd[ab.top().second]=1;
cd[i]=1;
ab.pop();
}
}
}
ll l=0;
for(ll i=0;i<f.size();i++)
{
if(cd[i]==0)
cout<<f[i];
else
l++;
cd[i]=0;
}
if(l==f.size())
cout<<"Perfect";
cout<<endl;
cout<<cnt<<endl;
for(ll i=1;i<=cnt;i++)
{
cout<<ans[i].first+1<<" "<<ans[i].second.first+1<<" "<<ans[i].second.second+1<<endl;
}
}
}
[APC001] D - Array Again
线段树+map维护,先用vector存储输入信息,然后离散化用map映射,最后敲线段树+lazy标志即可解决
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<queue>
#include<deque>
#include<math.h>
#include<map>
#include<stack>
#include<set>
#include<vector>
#include<random>
using namespace std;
typedef long long ll;
const ll maxn = 1e5+10;
void fio()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
ll ksm(ll x,ll y)
{
ll ans=1;
while(y)
{
if(y&1)
ans*=x;
x*=x;
y>>=1;
}
return ans;
}
ll gcd(ll x,ll y)
{
if(y==0)
return x;
else
return gcd(y,x%y);
}
struct s
{
ll l,r;
ll cs;
ll lazy=0;
}p[maxn<<2];
ll fa[maxn<<2];
void build(ll i,ll l,ll r)
{
p[i].l=l;p[i].r=r;
p[i].cs=0;p[i].lazy=0;
if(l==r)
{
fa[l]=i;
return ;
}
build(i<<1,l,(l+r)>>1);
build(i<<1|1,(l+r>>1)+1,r);
}
void push_down(ll i)
{
if(p[i].lazy)
{
p[i<<1].lazy=1;
p[i<<1|1].lazy=1;
p[i].cs=1;
if(p[i<<1].cs>0)
p[i<<1].cs=1;
if(p[i<<1|1].cs>1)
p[i<<1|1].cs=1;
p[i].lazy=0;
}
}
void upd(ll i,ll x,ll gs)
{
if(p[i].l==p[i].r)
{
p[i].cs+=gs;
//cout<<p[i].cs<<endl;
return;
}
push_down(i);
ll mid=(p[i].l+p[i].r)>>1;
ll i1=i<<1;
ll i2=i<<1|1;
if(x<=mid)
upd(i1,x,gs);
if(x>=mid+1)
upd(i2,x,gs);
p[i].cs=p[i1].cs+p[i2].cs;
//cout<<p[i].cs<<endl;
}
void dt(ll i, ll x,ll gs)
{
if (p[i].l == p[i].r)
{
p[i].cs-=gs;
p[i].cs=max(p[i].cs,(ll)0);
return;
}
push_down(i);
ll mid = (p[i].l + p[i].r) >> 1;
ll i1 = i << 1;
ll i2 = i << 1 | 1;
if (x <= mid)
dt(i1, x,gs);
if (x >= mid + 1)
dt(i2, x,gs);
p[i].cs = p[i1].cs + p[i2].cs;
}
ll query(ll i,ll l,ll r)
{
ll ans=0;
if(l==p[i].l&&p[i].r==r)
{
ans+=p[i].cs;
return ans;
}
push_down(i);
ll i1=i<<1;
ll i2=i<<1|1;
if(l<=p[i1].r)
{
if(r<=p[i1].r)
{
ans+=query(i1,l,r);
}
else
ans+=query(i1,l,p[i1].r);
}
if(r>=p[i2].l)
{
if(l>=p[i2].l)
ans+=query(i2,l,r);
else
ans+=query(i2,p[i2].l,r);
}
return ans;
}
vector<pair<ll,pair<ll,ll>>>g;
set<ll>q;
map<ll,ll>f;
int main()
{
fio();
ll t;
cin>>t;
build(1,1,t);
while(t--)
{
ll op;
cin>>op;
if(op==1)
{
ll x,y;
cin>>x>>y;
g.push_back({1,{x,y}});
q.insert(x);
}
else if(op==2)
{
ll x,y ;
cin>>x>>y;
g.push_back({2,{x,y}});
q.insert(x);
}
else if(op==3)
{
g.push_back({3,{0,0}});
}
else
{
ll x;
cin>>x;
g.push_back({4,{x,0}});
q.insert(x);
}
}
ll cnt=0;
for(auto j:q)
{
cnt++;
f[j]=cnt;
}
for(auto j:g)
{
ll op=j.first;
ll op1=j.second.first;
ll op2=j.second.second;
if(op==1)
{
upd(1,f[op1],op2);
}
else if(op==2)
{
dt(1,f[op1],op2);
}
else if(op==3)
{
p[1].lazy=1;
}
else
{
cout<<query(1,f[op1],f[op1])<<endl;
}
}
}
标签:ABC,return,Contest,题解,ll,cin,else,ans,include
From: https://www.cnblogs.com/cjcf/p/18443310