牛客小白月赛81
A.小辰打比赛
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n , x , y , sum;
cin >> n >> x; sum = 0;
for(int i = 1 ; i <= n ; ++i)
{
cin >> y;
if(y < x)
sum += y;
}
cout << sum << '\n'; return 0;
}
B.小辰的圣剑
#include<iostream>
using namespace std;
const int N = 5010;
int n;
long long m , u;
int A[N] , B[N];
int main()
{
int Max = 0;
cin >> n >> m >> u;
for(int i = 1 ; i <= n ; ++i)
cin >> A[i];
for(int i = 1 ; i <= n ; ++i)
cin >> B[i];
for(int i = 1 ; i <= n ; ++i)
{
int j = i;
long long res_u = 0ll , res_m = m;
while(j <= n)
{
if(res_m >= A[j] && res_u + B[j] <= u)
{
res_m -= A[j]; res_u += B[j];
}
else
break;
j++;
}
Max = max(Max , j - i);
}
cout << Max << '\n';
}
C.陶陶学算术
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e5+10;
int tot;
int prime[MAXN] , vis[MAXN] , Output1[MAXN] , Output2[MAXN];
void Init()
{
int n = 1e5;
for(int i = 2 ; i <= n ; ++i)
{
if(!vis[i]) prime[++tot] = i;
for(int j = 1 ; j <= tot && i * prime[j] <= n ; ++j)
{
vis[i * prime[j]] = 1;
if(i * prime[j] == 0)
break;
}
}
}
void Solve(int f[] , int &flag)
{
int m , op , x;
flag = 0;
cin >> m;
while(m--)
{
cin >> op >> x;
if(x < 0)
x = -x , flag ^= 1;
for(int i = 1 ; prime[i] * prime[i] <= x ; ++i)
{
if(x % prime[i] == 0)
{
int cnt = 0;
while(x % prime[i] == 0) x /= prime[i] , cnt++;
if(op == 1)
f[i] += cnt;
else
f[i] -= cnt;
}
}
if(x > 1)
{
int y = lower_bound(prime + 1 , prime + 1 + tot , x) - prime;
if(op == 1)
f[y]++;
else
f[y]--;
}
}
}
int main()
{
int flag1 , flag2;
Init();
Solve(Output1 , flag1);
Solve(Output2 , flag2);
if(flag1 != flag2) { cout << "NO" << '\n'; return 0; }
for(int i = 1 ; i <= tot ; ++i)
if(Output1[i] != Output2[i]) { cout << "NO" << '\n'; return 0; }
cout << "YES" << '\n';
return 0;
}
D.小辰的借钱计划
#include<bits/stdc++.h>
using namespace std;
int Solve()
{
int m , a , tot_case;
long long Sum;
cin >> m >> a;
tot_case = 0; Sum = 0ll;
for(int i = a + a ; i + a <= m ; i += a)
Sum += i , tot_case++;
for(int i = 1 ; i * i <= a ; ++i)
{
if(a % i == 0)
{
if(a + i <= m)
tot_case++ , Sum += i;
if(i * i != m && a + a / i <= m)
tot_case++ , Sum += a / i;
}
}
if(Sum > 1ll * a * tot_case)
cout << "YES" << '\n';
else
cout << "NO" << '\n';
return 0;
}
int main()
{
int T; cin >> T; while(T--) Solve();
return 0;
}
E.小辰的智慧树
Error
人菜但题水,第54行的判断应该是不会成立的,但是交上去之后发现只过了20%多一点。
但是注释掉之后居然能过。
先留个坑,若有大佬路过,感谢指正。
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6+10;
int n;
long long m;
int p[N];
struct Node{
int h , c;
}A[N];
bool cmp(int x , int y) { return A[x].h > A[y].h; }
long long Check(int mid)
{
long long res = 0ll;
for(int i = 1 ; i <= n ; ++i)
res += max(A[i].h - max(A[i].c , mid) , 0);
return res;
}
int main()
{
ios::sync_with_stdio(false); cin.tie(0);
int l , r , mid , tot;
long long res , Answer;
cin >> n >> m;
for(int i = 1 ; i <= n ; ++i)
cin >> A[i].h >> A[i].c;
l = 0; r = 1e6;
while(l < r)
{
mid = (l + r) >> 1;
if(Check(mid) <= m)
r = mid;
else
l = mid + 1;
}
Answer = res = 0ll;
for(int i = 1 ; i <= n ; ++i)
{
if(A[i].h > max(l , A[i].c))
{
int x = A[i].h - max(l , A[i].c);
Answer += 1ll * x * (2 * A[i].h - x);
res += x;
}
}
res = m - res;
tot = 0;
for(int i = 1 ; i <= n ; ++i)
if(l > A[i].c)
p[++tot] = i;
sort(p + 1 , p + 1 + tot , cmp);
if(Check(l - 1) <= m)
cout << "NO" << '\n';
for(long long i = 1 ; i <= min(res , 1ll * tot) ; ++i)
{
int x = A[p[i]].h - l;
Answer -= 1ll * x * (2 * A[p[i]].h - x);
Answer += 1ll * (x + 1) * (2 * A[p[i]].h - (x + 1));
}
cout << Answer << '\n';
return 0;
}
F.小辰刚学 gcd
这题目中数据范围\(1 <= a_i <= 2^{31}\),good。刚好比int最大值大1.
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
const int N = 6e5+10;
#define int long long
int n , m;
long long Array[N];
vector< pair<int,int> > Gcd[N];
signed main()
{
ios::sync_with_stdio(false); cin.tie(0);
unordered_map<long long,int> Visit;
int l , r , tmp;
cin >> n >> m;
for(int i = 1 ; i <= n ; ++i)
cin >> Array[i];
for(int i = 1 ; i <= n ; ++i)
{
Gcd[i].push_back(make_pair(Array[i],i));
Visit[Array[i]] = i;
for(auto x:Gcd[i-1])
{
tmp = __gcd(x.first , Array[i]);
if(!Visit.count(tmp) || Visit[tmp] != i)
{
Visit[tmp] = i;
Gcd[i].push_back(make_pair(tmp , x.second));
}
}
}
while(m--)
{
int cnt = 0;
cin >> l >> r;
for(auto x:Gcd[r])
if(x.second >= l)
cnt++;
else
break;
cout << cnt << '\n';
}
return 0;
}
/*
6 1
3 3 3 6 5 6
1 6
*/
标签:std,prime,int,tot,牛客,long,小白月赛,using,81
From: https://www.cnblogs.com/sybs5968QAQ/p/17839801.html