口算训练
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <string>
#include <map>
#include <cmath>
#include <vector> #define Faster ios::sync_with_stdio(false),cin.tie(0)
#define Read freopen("in.txt","r",stdin),freopen("out.txt","w",stdout)
#define Close fclose(stdin),fclose(stdout)
const int maxn = 1e5 + ;
using namespace std;
const int MOD = 1e9+;
typedef long long ll; vector<int> g[maxn];
//下标肯定是从小到大按顺序的 void res(int id, int x){
for(int i = ;i*i <= x;i++){
while(x%i == ){
g[i].push_back(id);
x /= i;
}
}
if(x > )
g[x].push_back(id);
} int query(int l,int r, int x){
return upper_bound(g[x].begin(), g[x].end(), r) - lower_bound(g[x].begin(),g[x].end(), l);
} void init(){
for(int i = ;i < maxn;i++)
g[i].clear();
} int main(){
// Faster;
int t;
// cin >> t;
scanf("%d", &t);
while(t--){
init();
int n, q;
scanf("%d%d", &n, &q);
for(int i = ;i <= n;i++){
int x;
// cin >> x;
scanf("%d", &x);
res(i, x);
}
while(q--){
int l, r, d, num;
// cin >> l >> r >> d;
scanf("%d%d%d", &l, &r, &d);
bool ok = true;
for(int i = ;i*i <= d;i++){
int cnt = ;
while(d%i == ){
cnt++;
d /= i;
}
//因子为i 的数目 大于(l,r)中i 的个数
num = query(l, r, i);
if(cnt > num){
ok = false;
break;
}
}
if(ok && d > ){
num = query(l, r, d);
if(num == )
ok = false;
}
if(ok)
// cout << "Yes" << endl;
printf("Yes\n");
else
// cout << "No" << endl;
printf("No\n");
}
}
return ;
}
缺失的数据范围
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <string>
#include <map>
#include <cmath>
#include <vector> #define Faster ios::sync_with_stdio(false),cin.tie(0)
#define Read freopen("in.txt","r",stdin),freopen("out.txt","w",stdout)
#define Close fclose(stdin),fclose(stdout)
const int maxn = 1e4 + ;
using namespace std;
const int MOD = 1e9+;
typedef unsigned long long ll; int a, b;
ll k; bool check(ll x){
long double ans = ;
for(int i = ;i < a;i++){
ans *= x;
if(ans > k)
return false;
}
ll bb = ceil(log2(x));
for(int i = ;i < b;i++){
ans *= bb;
if(ans > k)
return false;
}
return true;
} int main(){
Faster;
int n;
cin >> n;
while(n--){
cin >> a >> b >> k;
ll l = ;
ll r = k;
while(l <= r){
ll mid = (l+r)/;
if(check(mid)){
l = mid+;
}
else{
r = mid-;
}
}
cout << r << endl;
}
return ;
}
赛题分析
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <string>
#include <map>
#include <cmath>
#include <vector> #define Faster ios::sync_with_stdio(false),cin.tie(0)
#define Read freopen("in.txt","r",stdin),freopen("out.txt","w",stdout)
#define Close fclose(stdin),fclose(stdout)
const int maxn = 1e4 + ;
using namespace std;
const int MOD = 1e9+;
typedef long long ll; #define INF 0xfffffff int main(){
Faster;
int t;
cin >> t;
int cnt = ;
while(t--){
int n, m;
cin >> n >> m;
int Min1 = INF;
int Min2 = INF;
for(int i = ;i < n;i++){
int x;
cin >> x;
if(x < Min1){
Min1 = x;
}
}
for(int i = ;i < m;i++){
int x;
cin >> x;
if(x < Min2){
Min2 = x;
}
}
cout << "Problem " << ++cnt << ":" << endl;
cout << "Shortest judge solution: " << Min1 << " bytes." << endl;
if(Min2 == INF)
cout << "Shortest team solution: N/A bytes." << endl;
else
cout << "Shortest team solution: " << Min2 << " bytes." << endl;
}
return ;
}
SA-IS后缀数组
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <string>
#include <map>
#include <cmath>
#include <vector> #define Faster ios::sync_with_stdio(false),cin.tie(0)
#define Read freopen("in.txt","r",stdin),freopen("out.txt","w",stdout)
#define Close fclose(stdin),fclose(stdout)
const int maxn = 1e4 + ;
using namespace std;
const int MOD = 1e9+;
typedef long long ll; int main(){
Faster;
int t;
cin >> t;
while(t--){
int n;
cin >> n;
string s;
cin >> s;
int cnt = ;
for(int i = ;i < n-;i++){
if(s[i] == s[i+]){
cnt++;
}
else if(s[i] < s[i+]){
cnt++;
while(cnt){
cnt--;
cout << "<";
}
}
else if(s[i] > s[i+]){
cnt++;
while(cnt){
cnt--;
cout << ">";
}
}
}
while(cnt--){
cout << ">";
}
cout << endl;
}
return ;
}