Dashboard - Codeforces Round 969 (Div. 2) - Codeforces
A. Dora's Set
题目大意:
给定l,r,求l,r中能选出多少个三元组,每个数两两互质
思路:
这三个数中至少有两个奇数,因此我们数一数有cnt个奇数,cnt/2就代表最多能有多少个组。每两个奇数配一个偶数,给cnt/2和偶数个数求个最小值就是最多有多少组。
#include<bits/stdc++.h>
using ll = long long;
using ull = unsigned long long;
using ari = std::array<int, 3>;
using PII = std::pair<int, int>;
const int N = 2e5 + 10;
const int mod = 1e9 + 7;
const double eps = 1e-6;
int n,a[N];
bool st[N];
void solve() {
int l,r;
std::cin>>l>>r;
ll ans=0;
int cnt=0;
for(int i=l;i<=r;i++)
{
if(i%2) cnt++;
}
ans=std::min(cnt/2,(r-l+1-cnt));
std::cout<<ans<<'\n';
}
signed main() {
std::ios::sync_with_stdio(0);
std::cin.tie(0);
int t = 1;
std::cin>>t;
while (t--) {
solve();
}
return 0;
}
B. Index and Maximum Value
题目大意:
给定数组a,每次操作对a数组中在l-r范围内的数字+1或者-1,求每次操作过后a数组中的最大值
#include<bits/stdc++.h>
using ll = long long;
using ull = unsigned long long;
using ari = std::array<int, 3>;
using PII = std::pair<int, int>;
const int N = 2e5 + 10;
const int mod = 1e9 + 7;
const double eps = 1e-6;
int n,m;
int a[N],d[N];
void solve() {
std::cin>>n>>m;
std::map<int,int> mp;
int maxn=0,minn=INT_MAX;
for(int i=0;i<n;i++)
{
std::cin>>a[i];
maxn=std::max(maxn,a[i]);
minn=std::min(minn,a[i]);
}
while(m--)
{
int l,r;
char op;
std::cin>>op;
std::cin>>l>>r;
if(op=='+'){
if(l<=maxn&&r>=maxn){
maxn++;
}
std::cout<<maxn<<" ";
}else{
if(l<=maxn&&r>=maxn){
maxn--;
}
std::cout<<maxn<<" ";
}
}
std::cout<<'\n';
}
signed main() {
std::ios::sync_with_stdio(0);
std::cin.tie(0);
int t = 1;
std::cin>>t;
while (t--) {
solve();
}
return 0;
}