A - I love cube
数学
数学题 , 由给的样例一个边长为1的小正方体联想到一个去分割一个大的正方体 , 由顶点必须是整数点,则在正方体的三个主边上找相应长度的起点即可
枚举每一个长度,得到正方体种类:是从1 的 3次方 加到 n 的3次方。
1
3
+
2
3
+
3
3
+
…
…
+
n
3
=
[
n
(
n
+
1
)
/
2
]
2
1^3+2^3+3^3+……+n^3=[n(n+1)/2]^2
13+23+33+……+n3=[n(n+1)/2]2
由于数据比较大,采取分而算之的策略
#pragma GCC optimize(3,"Ofast","inline")
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef __uint128_t __128u;
const int N = 1e6+10 , INF = 0x3f3f3f3f , mod1 = 1e9 + 7 , mod2 = 1e9+9;
typedef pair<int , int> PII;
#define l first
#define r second
int a[N] , b[N];
int cmp(int a , int b){
return a > b;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);//输入加速
cout.tie(0);//输出加速
int t;
cin>>t;
while(t--){
ull n;
cin>>n;
n -= 1ull;
ull k1 = n % mod1;
ull k2 = (n + 1ull ) % mod1;
k1 = k1 * k1 % mod1;
k2 = k2 * k2 % mod1;
cout<<k1 * k2 % mod1 * 2 %mod1 <<endl;
}
}
E - I love string
模拟 , 数学
直接模拟操作过程即可,过程中能进行选择的性质只出现在前后都相等的时候 ,最后求一个快速幂
#pragma GCC optimize(3,"Ofast","inline")
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef __uint128_t __128u;
const int N = 1e6+10 , INF = 0x3f3f3f3f , p = 1e9 + 7 , mod2 = 1e9+9;
typedef pair<int , int> PII;
#define l first
#define r second
int a[N] , b[N];
int cmp(int a , int b){
return a > b;
}
ll qmi(ll a , ll k){
ll res = 1;
while(k){
if(k & 1) res = res * a % p;
a = a * a % p;
k >>= 1ll;
}
return res;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);//输入加速
cout.tie(0);//输出加速
int t;
cin>>t;
while(t--){
int n;
cin>>n;
string s;
cin>>s;
deque<char>op;
int ans = 0;
op.push_back(s[0]);
for(int i = 1 ; i < s.size() ; i++){
if(s[i] == op.front() && s[i] == op.back()){
op.push_back(s[i]);
ans++;
}
else if(s[i] <= op.front()) op.push_front(s[i]);
else op.push_back(s[i]);
}
cout<<qmi(2 , ans)<<endl;
}
}
L - I love 114514
字符串匹配 ,直接用find()
#pragma GCC optimize(3,"Ofast","inline")
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef __uint128_t __128u;
const int N = 1e6+10 , INF = 0x3f3f3f3f , mod1 = 1e9 + 7 , mod2 = 1e9+9;
typedef pair<int , int> PII;
#define l first
#define r second
int a[N] , b[N];
int cmp(int a , int b){
return a > b;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);//输入加速
cout.tie(0);//输出加速
int t;
cin>>t;
while(t--){
string s1;
cin>>s1;
string s2 = "114514";
if(s1.find(s2) == s1.npos) cout<<"Abuchulaile"<<endl;
else cout<<"AAAAAA"<<endl;
}
}
K - I love max and multiply
dp , 二进制
对 i & j >= k 可以枚举 k 那些状态可以更新 k 每次存 该状态以及以上面可以更新这个状态的最大值 和最小值 , 最后进行计算。
#pragma GCC optimize(3,"Ofast","inline")
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef __uint128_t __128u;
const int N = 1e6+10 , INF = 0x3f3f3f3f , mod1 = 1e9 + 7 , mod2 = 1e9+9 , p = 998244353;
typedef pair<int , int> PII;
#define l first
#define r second
ll a[N] , b[N] , c[N];
int cmp(int a , int b){
return a > b;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);//输入加速
cout.tie(0);//输出加速
int t;
cin>>t;
while(t--){
int n;
cin>>n;
ll A[N][3] , B[N][3];
for(int i = 0 ; i < n ; i++) cin>>a[i];
for(int i = 0 ; i < n ; i++) cin>>b[i];
for(int i = n - 1 ; i >= 0 ; i--){
c[i] = -1e18 - 10;
A[i][1] = A[i][2] = a[i];
B[i][1] = B[i][2] = b[i];
}
for(int i = n - 1 ; i >= 0 ; i--){
c[i] = max(c[i] , a[i]*b[i]);
for(int j = 0 ; j <= 18 ; j++){
if(i >> j & 1){
int k = i - (1 << j);
A[k][1] = max(A[i][1] ,A[k][1]);
A[k][2] = min(A[i][2] , A[k][2]);
B[k][1] = max(B[i][1] ,B[k][1]);
B[k][2] = min(B[i][2] , B[k][2]);
}
}
}
for(int k = n- 1 ;k >= 0 ; k--){
ll m = max(A[k][1] * B[k][1] , A[k][2] * B[k][2]);
m = (ll)max((ll)max(A[k][2] * B[k][1] , A[k][1] * B[k][2]) , m);
c[k] = max(c[k] , m);
}
for(int i = n -2 ;i >= 0 ; i--) c[i] = max(c[i] , c[i+1] );
ll ans = 0;
for(int i =0 ;i < n ; i++){
ans += c[i]%p;
}
cout<<(ans%p + p) % p<<endl;
}
}