0.0先欠着题解0.0以后一定还
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6+10,mod=1e9+7;
#define int long long
typedef long long LL;
typedef pair<int, int> PII;
typedef unsigned long long ULL;
const long long inf=1e17;
using node=tuple<int,int,int>;
int n,m,k;
int a[N];
void solve()
{
cin>>n;
int mx=n/4;
if(n<4||n%4!=0&&n%4!=2)
{
cout<<"-1\n";return ;
}
int mn=n/6;
//0 2 4
if((n%6)%2==1){
cout<<"-1\n";
return ;
}
if(n%6>0) mn++;
cout<<mn<<" "<<mx<<"\n";
}
signed main()
{
cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
int t=1;
cin>>t;
while(t--) solve();
}
B
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6+10,mod=1e9+7;
#define int long long
typedef long long LL;
typedef pair<int, int> PII;
typedef unsigned long long ULL;
const long long inf=1e17;
using node=tuple<int,int,int>;
int n,m,k;
PII a[N];
void solve()
{
cin>>n>>m;
int now=0;
for(int i=1;i<=n;i++){
cin>>a[i].first;
a[i].second=0;
now+=a[i].first;
}
int lst=-1,idx=-1;
for(int i=1;i<=m;i++)
{
int op;
cin>>op;
if(op==1)
{
int x,y;
cin>>x>>y;
if(a[x].second>idx){
now-=a[x].first;
}else now-=lst;
a[x]={y,i};
now+=a[x].first;
}else
{
cin>>lst;
idx=i;
now=n*lst;
}
cout<<now<<"\n";
}
}
signed main()
{
cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
int t=1;
// cin>>t;
while(t--) solve();
}
C:
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6+10,mod=1e9+7;
#define int long long
typedef long long LL;
typedef pair<int, int> PII;
typedef unsigned long long ULL;
const long long inf=1e17;
using node=tuple<int,int,int>;
int n,m,k;
int x[N],y[N];
void solve()
{
cin>>n>>m;
set<int> stx,sty;
for(int i=1;i<=n;i++)
stx.insert(i),sty.insert(i);
stx.insert(2e9);sty.insert(2e9);
while(m--)
{
int op,x1,y1,x2,y2;
cin>>op;
if(op==1){
cin>>x1>>y1;
if(x[x1]==0) stx.erase(x1);
if(y[y1]==0) sty.erase(y1);
x[x1]++;
y[y1]++;
}
else if(op==2)
{
cin>>x1>>y1;
x[x1]--;y[y1]--;
if(x[x1]==0) stx.insert(x1);
if(y[y1]==0) sty.insert(y1);
}
else
{
bool ok=false;
cin>>x1>>y1>>x2>>y2;
auto it=stx.lower_bound(x1);
if(*it>x2) ok=true;
it=sty.lower_bound(y1);
if(*it>y2) ok=true;
if(ok) cout<<"Yes\n";
else cout<<"No\n";
}
}
}
signed main()
{
cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
int t=1;
// cin>>t;
while(t--) solve();
}
D
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6+10,M=2*N,mod=1e9+7;
#define int long long
typedef long long LL;
typedef pair<int, int> PII;
typedef unsigned long long ULL;
const long long inf=1e17;
using node=tuple<int,int,int>;
int n,m,k;
int a[N];
vector<int> g[N],G[N];
void solve()
{
cin>>n>>m>>k;
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=1;i<=m;i++)
{
int a,b;cin>>a>>b;
g[a].push_back(b);
}
auto check=[&](int need)
{
for(int i=1;i<=n;i++) G[i].clear();
//有向图判环
vector<int> d(n+10);
for(int i=1;i<=n;i++)
{
if(a[i]>need) continue;
for(auto v:g[i])
{
if(a[v]<=need){
G[i].push_back(v);
d[v]++;
}
}
}
queue<int> q;
for(int i=1;i<=n;i++)
{
if(d[i]==0&&a[i]<=need) q.push(i);
}
int len=0;
while(q.size())
{
int sz=q.size();
for(int i=0;i<sz;i++){
auto t=q.front();
q.pop();
for(auto v:G[t]){
if(--d[v]==0){
q.push(v);
}
}
}
len++;
if(len==k) return true;
}
for(int i=1;i<=n;i++)
{
if(d[i]) return true;
}
return false;
};
int l=1,r=1e9+10;
while(l<r){
int mid=l+r>>1;
if(check(mid)) r=mid;
else l=mid+1;
}
if(l==1e9+10) l=-1;
cout<<l<<"\n";
}
signed main()
{
cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
int t=1;
// cin>>t;
while(t--) solve();
}
E:
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6+10,M=2*N,mod=998244353;
#define int long long
typedef long long LL;
typedef pair<int, int> PII;
typedef unsigned long long ULL;
const long long inf=1e17;
using node=tuple<int,int,int>;
int n,m,k;
int qmi(int a, int k, int p) // 求a^k mod p
{
int res = 1 % p;
while (k)
{
if (k & 1) res = (LL)res * a % p;
a = (LL)a * a % p;
k >>= 1;
}
return res;
}
//int a[N];
//vector<int> g[N],G[N];
void solve()
{
const int m = 18;
int n; cin >> n;
string s; cin >> s;
int num = count(s.begin(), s.end(), '?');
int a[n + 1][n + 1];
int dp[n + 1][n + 1];
for (int i = 0; i <= n; i++) for (int j = 0; j <= n; j++)
a[i][j] = 0, dp[i][j] = num;
int cnt[1 << m][m];
for (int i = 0; i < (1 << m); i++) for (int j = 0; j < m; j++)
cnt[i][j] = 0;
for (int i = 1; i <= n; i++) {
for (int l = 0; l < n; l++) {
int r = l + i - 1; if (r >= n) break;
// 判断是否回文
dp[l][r] = -1;
if (s[l] != s[r] && s[l] != '?' && s[r] != '?') continue;
if (l != r) {
if (s[l] != '?' && s[r] != '?')
a[l][r] = a[l + 1][r - 1], dp[l][r] = dp[l + 1][r - 1];
if (s[l] == '?' && s[r] != '?')
a[l][r] = a[l + 1][r - 1] | (1 << (s[r] - 'a')),
dp[l][r] = dp[l + 1][r - 1] - 1;
if (s[l] != '?' && s[r] == '?')
a[l][r] = a[l + 1][r - 1] | (1 << (s[l] - 'a')),
dp[l][r] = dp[l + 1][r - 1] - 1;
if (s[l] == '?' && s[r] == '?')
a[l][r] = a[l + 1][r - 1], dp[l][r] = dp[l + 1][r - 1] - 1;
} else dp[l][r] = num;
if (dp[l][r] >= 0) //如果回文
for (int k = 1; k < m; k++)
{
cnt[a[l][r]][k] += qmi(k,dp[l][r],mod);
cnt[a[l][r]][k]%=mod;
}
}
}
// 高维前缀和
for (int i = 0; i < m; i++)
for (int j = 0; j < (1 << m); j++)
for (int k = 1; k < m; k++)
if ((1 << i) & j) {cnt[j][k] += cnt[(1 << i) ^ j][k];
cnt[j][k]%=mod;
}
int q;
cin >> q;
while (q--) {
string s1; cin >> s1;
int t = 0;
for (auto it : s1) t += (1 << (it - 'a'));
cout << cnt[t][s1.length()]%mod << '\n';
}
}
signed main()
{
cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
int t=1;
// cin>>t;
while(t--) solve();
}