A
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int P = 998244353;
double solve(){
double a,b,c,x;
cin>>a>>b>>c>>x;
if(x<=a) return 1;
else if(x>b) return 0;
else return c/(b-a);
}
int main(){
cout<<solve();
}
B
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int P = 998244353;
int main(){
string s;
cin>>s;
sort(s.begin(),s.end());
cout<<s<<endl;
}
C
直接动态规划即可,注意细节
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int P = 998244353;
using i64 = long long;
// assume -P <= x < 2P
int norm(int x) {
if (x < 0) {
x += P;
}
if (x >= P) {
x -= P;
}
return x;
}
template<class T>
T power(T a, int b) {
T res = 1;
for (; b; b /= 2, a *= a) {
if (b % 2) {
res *= a;
}
}
return res;
}
struct Z {
int x;
Z(int x = 0) : x(norm(x)) {}
int val() const {
return x;
}
Z operator-() const {
return Z(norm(P - x));
}
Z inv() const {
assert(x != 0);
return power(*this, P - 2);
}
Z &operator*=(const Z &rhs) {
x = ll(x) * rhs.x % P;
return *this;
}
Z &operator+=(const Z &rhs) {
x = norm(x + rhs.x);
return *this;
}
Z &operator-=(const Z &rhs) {
x = norm(x - rhs.x);
return *this;
}
Z &operator/=(const Z &rhs) {
return *this *= rhs.inv();
}
friend Z operator*(const Z &lhs, const Z &rhs) {
Z res = lhs;
res *= rhs;
return res;
}
friend Z operator+(const Z &lhs, const Z &rhs) {
Z res = lhs;
res += rhs;
return res;
}
friend Z operator-(const Z &lhs, const Z &rhs) {
Z res = lhs;
res -= rhs;
return res;
}
friend Z operator/(const Z &lhs, const Z &rhs) {
Z res = lhs;
res /= rhs;
return res;
}
};
Z dp[1000100][10];
int main(){
int n;
cin>>n;
Z ans=0;
for( int i=1;i<=9;i++) dp[1][i]=1;
for( int i=2;i<=n;i++){
for( int j=1;j<=9;j++){
if(j==1) dp[i][j]=dp[i-1][2]+dp[i-1][1];
else if(j==9) dp[i][j]=dp[i-1][9]+dp[i-1][8];
else {
dp[i][j]=dp[i-1][j]+dp[i-1][j+1]+dp[i-1][j-1];
}
}
}
for( int i=1;i<=9;i++){
ans+=dp[n][i];
}
cout<<ans.val()<<endl;
return 0;
}
D
没写
E
直接动态规划
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int P = 998244353;
using i64 = long long;
// assume -P <= x < 2P
int norm(int x) {
if (x < 0) {
x += P;
}
if (x >= P) {
x -= P;
}
return x;
}
template<class T>
T power(T a, int b) {
T res = 1;
for (; b; b /= 2, a *= a) {
if (b % 2) {
res *= a;
}
}
return res;
}
struct Z {
int x;
Z(int x = 0) : x(norm(x)) {}
int val() const {
return x;
}
Z operator-() const {
return Z(norm(P - x));
}
Z inv() const {
assert(x != 0);
return power(*this, P - 2);
}
Z &operator*=(const Z &rhs) {
x = ll(x) * rhs.x % P;
return *this;
}
Z &operator+=(const Z &rhs) {
x = norm(x + rhs.x);
return *this;
}
Z &operator-=(const Z &rhs) {
x = norm(x - rhs.x);
return *this;
}
Z &operator/=(const Z &rhs) {
return *this *= rhs.inv();
}
friend Z operator*(const Z &lhs, const Z &rhs) {
Z res = lhs;
res *= rhs;
return res;
}
friend Z operator+(const Z &lhs, const Z &rhs) {
Z res = lhs;
res += rhs;
return res;
}
friend Z operator-(const Z &lhs, const Z &rhs) {
Z res = lhs;
res -= rhs;
return res;
}
friend Z operator/(const Z &lhs, const Z &rhs) {
Z res = lhs;
res /= rhs;
return res;
}
};
Z solve(){
int n;
cin>>n;
string s;
cin>>s;
vector<Z>dp(n+1);
int len=s.size();
for( int i=0;i<len/2;i++){
dp[i]=Z(s[i]-'A')*power(Z(26),(len/2-i-1)+len%2);
}
Z ans=0;
if(len%2){
ans+=(int)s[len/2]-'A';
}
int good=1;
for( int i=len/2-1;i>=0;i--){
if(s[i]==s[len-i-1]) continue;
else if(s[i]<s[len-i-1]){
ans+=1;good=0;
break;
}
else {
good=0;break;
}
}
if(good) ans+=1;
for( int i=0;i<len;i++){
ans+=dp[i];
}
return ans;
}
int main(){
int t;
cin>>t;
while(t--){
cout<<solve().val()<<endl;
}
return 0;
}
F
容斥原理。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int P = 998244353;
using i64 = long long;
// assume -P <= x < 2P
int norm(int x) {
if (x < 0) {
x += P;
}
if (x >= P) {
x -= P;
}
return x;
}
template<class T>
T power(T a, int b) {
T res = 1;
for (; b; b /= 2, a *= a) {
if (b % 2) {
res *= a;
}
}
return res;
}
struct Z {
int x;
Z(int x = 0) : x(norm(x)) {}
int val() const {
return x;
}
Z operator-() const {
return Z(norm(P - x));
}
Z inv() const {
assert(x != 0);
return power(*this, P - 2);
}
Z &operator*=(const Z &rhs) {
x = ll(x) * rhs.x % P;
return *this;
}
Z &operator+=(const Z &rhs) {
x = norm(x + rhs.x);
return *this;
}
Z &operator-=(const Z &rhs) {
x = norm(x - rhs.x);
return *this;
}
Z &operator/=(const Z &rhs) {
return *this *= rhs.inv();
}
friend Z operator*(const Z &lhs, const Z &rhs) {
Z res = lhs;
res *= rhs;
return res;
}
friend Z operator+(const Z &lhs, const Z &rhs) {
Z res = lhs;
res += rhs;
return res;
}
friend Z operator-(const Z &lhs, const Z &rhs) {
Z res = lhs;
res -= rhs;
return res;
}
friend Z operator/(const Z &lhs, const Z &rhs) {
Z res = lhs;
res /= rhs;
return res;
}
};
Z solve(){
int n,m,b,w;
cin>>n>>m>>b>>w;
vector<Z> fac(2510), invfac(2510);
fac[0] = 1;
for (int i = 1; i <= 2500; i++) {
fac[i] = fac[i - 1] * i;
}
invfac[2500] = fac[2500].inv();
for (int i = 2500; i; i--) {
invfac[i - 1] = invfac[i] * i;
}
auto C=[&](int x,int y)->Z{
if(y>x) return 0;
return fac[x]*invfac[x-y]*invfac[y];
};
Z ans=0;
for( int i=0;i<=n;i++){
for( int i2=0;i+i2<=n;i2++){
for( int j=0;j<=m;j++){
for( int j2=0;j+j2<=m;j2++){
Z cur=0;
cur=C(n,i)*C(n-i,i2)*C(m,j)*C(m-j,j2)*C(i*j,b)*C(j2*i2,w);
cur*=((i+i2+j+j2+m+n)%2)?-1:1;
ans+=cur;
//cout<<ans.val()<<endl;
}
}
}
}
return ans;
}
int main(){
cout<<solve().val();
return 0;
}
G
莫队
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int Q=1000100;
const int N=100100;
const int len=330;
struct interval{
int l,r;
int id;//记录是第几个问题
}q[Q];
vector<int>v(N);
int get( int x){
return x/len;
}
bool cmp(interval a,interval b){
if(get(a.l)!=get(b.l)) return get(a.l)<get(b.l);
else return a.r<b.r;
}
vector<int>cur(N);
void add(int val,int &res){
cur[val]++;
if(cur[val]%2==0) res++;
}
void del(int val,int &res){
cur[val]--;
if(cur[val]%2==1) res--;
}
int main(){
int n;
cin>>n;
for( int i=1;i<=n;i++){
cin>>v[i];
}
int m;
cin>>m;
for( int i=0;i<m;i++){
int l,r;
scanf("%d%d",&l,&r);
l,r;
q[i].l=l,q[i].r=r,q[i].id=i;
}
vector<int>ans(m);
sort(q,q+m,cmp);
int res=0;
for( int i=0,pl=1,pr=0;i<m;i++){
int id=q[i].id,l=q[i].l,r=q[i].r;
while(pr>r) del(v[pr--],res);
while(pr<r) add(v[++pr],res);
while(pl>l) add(v[--pl],res);
while(pl<l) del(v[pl++],res);
ans[id]=res;
}
for(auto i:ans){
cout<<i<<"\n";
}
return 0;
}