A
签到
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define lowbit(x) ((x)&(-(x)))
#define foru(i,begin,end) for(i=begin;i<=end;i++)
#define ford(i,begin,end) for(i=begin;i>=end;i--)
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define maxheap(x) priority_queue<x,vector<x>,less<x> >
#define minheap(x) priority_queue<x,vector<x>,greater<x> >
#define endl '\n'
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef long long ll;
typedef unsigned long long ull;
//#define mod 1000000009
//#define mod 1000000007
int a[100005];
int main()
{
int n,m;
cin>>n>>m;
int i;
for(i=1;i<=n;i++) cin>>a[i];
ll res=0;
for(i=1;i<=m;i++)
{
int x;
cin>>x;
res+=a[x];
}
cout<<res<<endl;
return 0;
}
B
签到
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define lowbit(x) ((x)&(-(x)))
#define foru(i,begin,end) for(i=begin;i<=end;i++)
#define ford(i,begin,end) for(i=begin;i>=end;i--)
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define maxheap(x) priority_queue<x,vector<x>,less<x> >
#define minheap(x) priority_queue<x,vector<x>,greater<x> >
#define endl '\n'
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef long long ll;
typedef unsigned long long ull;
//#define mod 1000000009
//#define mod 1000000007
int main()
{
int t;
cin>>t;
while(t--)
{
int x,y;
cin>>x>>y;
if(x%3!=y%3)
{
cout<<"No"<<endl;
}
else
cout<<"Yes"<<endl;
}
return 0;
}
C
特判全为 的情况,能取 时尽量取 ,否则取最小的数。
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define lowbit(x) ((x)&(-(x)))
#define foru(i,begin,end) for(i=begin;i<=end;i++)
#define ford(i,begin,end) for(i=begin;i>=end;i--)
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define maxheap(x) priority_queue<x,vector<x>,less<x> >
#define minheap(x) priority_queue<x,vector<x>,greater<x> >
#define endl '\n'
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef long long ll;
typedef unsigned long long ull;
//#define mod 1000000009
//#define mod 1000000007
int main()
{
int t;
cin>>t;
while(t--)
{
string s;
cin>>s;
string ans;
int i;
if(s.size()==1)
{
cout<<'1'<<endl;
continue;
}
for(i=0;i<s.size();i++) ans.push_back('0');
string tmp=ans;
for(i=0;i<s.size();i++)
{
if(s[i]=='0')
{
ans[i]='1';
}
}
if(ans!=tmp)
{
goto A;
}
for(i=s.size()-1;i>=0;i--)
{
if(s[i]=='0') continue;
if(s[i]=='1')
{
ans[i]='2';
}
else ans[i]='1';
break;
}
if(tmp==ans)
{
cout<<1<<endl;
continue;
}
A:
int flag=0;
for(auto i:ans)
{
if(!flag&&i=='0') continue;
if(i!='0') flag=1;
cout<<i;
}
cout<<endl;
}
return 0;
}
D
状态压缩暴力
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define lowbit(x) ((x)&(-(x)))
#define foru(i,begin,end) for(i=begin;i<=end;i++)
#define ford(i,begin,end) for(i=begin;i>=end;i--)
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define maxheap(x) priority_queue<x,vector<x>,less<x> >
#define minheap(x) priority_queue<x,vector<x>,greater<x> >
#define endl '\n'
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef long long ll;
typedef unsigned long long ull;
//#define mod 1000000009
//#define mod 1000000007
#define mod 998244353
struct node
{
int l,r;
}a[15];
int yes[15];
int n,m;
ll dp[1<<12];
ll tmp[100005];
ll ans[100005];
bool check(int x)
{
memset(yes,0,sizeof(yes));
int i,j;
for(i=0;i<m;i++)
{
if(x&(1<<i)) yes[i+1]=1;
}
for(i=0;i<=n;i++) tmp[i]=ans[i]=0;
for(i=1;i<=m;i++)
{
if(yes[i]) tmp[a[i].l]++,tmp[a[i].r+1]--;
}
for(i=1;i<=n;i++)
{
ans[i]=ans[i-1]+tmp[i];
if(ans[i]<2) return 0;
}
return 1;
}
int main()
{
cin>>n>>m;
int i,j;
for(i=1;i<=m;i++)
{
cin>>a[i].l>>a[i].r;
}
for(i=0;i<1<<m;i++)
{
if(dp[i])
{
continue;
}
else
{
if(check(i))
{
dp[i]=1;
}
}
}
ll res=0;
for(i=1;i<1<<m;i++)
{
if(dp[i]) res++;
res%=mod;
}
cout<<res;
return 0;
}
E
由于 很小,每次询问枚举最后一个 问题的序号,用大顶堆维护最小值即可。
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define lowbit(x) ((x)&(-(x)))
#define foru(i,begin,end) for(i=begin;i<=end;i++)
#define ford(i,begin,end) for(i=begin;i>=end;i--)
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define maxheap(x) priority_queue<x,vector<x>,less<x> >
#define minheap(x) priority_queue<x,vector<x>,greater<x> >
#define endl '\n'
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef long long ll;
typedef unsigned long long ull;
//#define mod 1000000009
//#define mod 1000000007
ll a[100005],b[100005];
ll sum[100005];
int main()
{
int n,q;
cin>>n>>q;
int i;
for(i=1;i<=n;i++) cin>>a[i];
for(i=1;i<=n;i++) cin>>b[i];
for(i=1;i<=n;i++) sum[i]=sum[i-1]+a[i];
while(q--)
{
int x;
cin>>x;
ll res=0;
maxheap(int) q;
for(i=1;i<=x;i++)
{
q.push(b[i]);
res+=b[i];
}
ll now=res;
res+=sum[x];
for(i=x+1;i<=n;i++)
{
ll tmp=sum[i];
if(b[i]<q.top())
{
now-=q.top();
q.pop();
q.push(b[i]);
now+=b[i];
tmp+=now;
res=min(res,tmp);
}
}
cout<<res<<endl;
}
return 0;
}