daily 2
2023/8/30
daily codeforces
加载过慢请开启缓存,浏览器默认开启
CF 1667B
struct fenwick {
ll PartialSum[MAXN];
fenwick() {
for (int i = 0; i < MAXN; i++) PartialSum[i] = 0;
}
inline void add(ll index, ll increase) {
while (index < MAXN) {
PartialSum[index] = max(increase, PartialSum[index]);
index += index & -index;
}
}
inline ll get(int index) {
ll sum = -INF;
while (index) {
sum = max(sum, PartialSum[index]);
index -= index & -index;
}
return sum;
}
};
ll a[MAXN], ord[MAXN], dp[MAXN], sum[MAXN];
void solve() {
int T;
cin >> T;
int n;
fenwick tr;
while (T--) {
cin >> n;
vector<pii> pre;
for (int i = 1; i <= n; ++i) {
tr.PartialSum[i] = -INF;
}
for (int i = 1; i <= n; ++i) {
cin >> a[i];
sum[i] = sum[i - 1] + a[i];
pre.push_back({sum[i], -i});
}
sort(pre.begin(), pre.end());
for (int i = 1; i <= n; ++i) {
ord[-pre[i - 1].second] = i;
}
for (int i = 1; i <= n; ++i) {
dp[i] = dp[i - 1] + (a[i] > 0 ? 1 : (a[i] < 0 ? -1 : 0));
auto pp = tr.get(ord[i]);
dp[i] = max(dp[i], tr.get(ord[i]) + i);
if (sum[i] > 0) dp[i] = i;
tr.add(ord[i], dp[i] - i);
}
cout << dp[n] << '\n';
dp[0] = sum[0] = 0;
}
return ;
}
CF 900C
struct fenwick {
ll PartialSum[MAXN];
fenwick() {
for (int i = 0; i < MAXN; i++) PartialSum[i] = 0;
}
inline void add(ll index, ll increase) {
while (index < MAXN) {
PartialSum[index] += increase;
index += index & -index;
}
}
inline ll get(int index) {
ll sum = 0;
while (index) {
sum += PartialSum[index];
index -= index & -index;
}
return sum;
}
};
void solve() {
int n;
cin >> n;
vector<int> p(n + 1);
fenwick tr;
for (int i = 1; i <= n; ++i) {
cin >> p[i];
}
ll ans = -1, ans_i = 1;
int cur_max = -1;
vector<int> cnt(n + 1);
for (int i = 1; i <= n; ++i) {
cur_max = max(cur_max, p[i]);
int cur_num = tr.get(p[i]);
if (cur_num == i - 2) {
cnt[cur_max]++;
} else if (cur_num == i - 1){
cnt[cur_max]--;
}
tr.add(p[i], 1);
}
for (int i = 1; i <= n; ++i) {
if (cnt[i] > ans) {
ans = cnt[i];
ans_i = i;
}
}
cout << ans_i << '\n';
return;
}
CF 49A
#include<bits/stdc++.h>
using namespace std;
int main()
{
char ch;
bool flag=false;
while((ch=getchar())!=EOF)
{
if(ch=='A'||ch=='a'||ch=='E'||ch=='e'||ch=='I'||ch=='i'||ch=='O'||ch=='o'||ch=='U'||ch=='u'||ch=='V'||ch=='v'||ch=='Y'||ch=='y')
flag=true;
else if((ch>='A'&&ch<='Z')||(ch>='a'&&ch<='z'))
flag=false;
}
if(flag)
cout<<"YES";
else
cout<<"NO";
return 0;
}
CF 46A
#include<iostream>
using namespace std;
int main(){
int n,I=1,a[100];
cin>>n;
for(int i=1;i<=n-1;i++){
I=I+i;
if(I>n)
I=I-n;
a[i]=I;
}
for(int i=1;i<=n-1;i++)
cout<<a[i]<<' ';
}
CF 1065C
struct fenwick {
ll PartialSum[MAXN];
fenwick() {
for (int i = 0; i < MAXN; i++) PartialSum[i] = 0;
}
inline void add(ll index, ll increase) {
while (index < MAXN) {
PartialSum[index] += increase;
index += index & -index;
}
}
inline ll get(int index) {
ll sum = 0;
while (index) {
sum += PartialSum[index];
index -= index & -index;
}
return sum;
}
};
void solve() {
int n, k, ans = 0;
cin >> n >> k;
fenwick tr;
vector<int> h(n + 1);
int maxx = INT_MIN, minx = INT_MAX;
for (int i = 1; i <= n; ++i) {
cin >> h[i];
maxx = max(maxx, h[i]);
minx = min(minx, h[i]);
tr.add(1, 1);
tr.add(h[i] + 1, -1);
}
if (maxx == minx) {
cout << 0 << '\n';
return;
}
ll sum = 0;
bool flag = true;
for (int i = maxx; i >= minx; --i) {
auto cur = tr.get(i); //how many shits is greater or equal than height i
if (cur + sum > k) {
ans++;
sum = cur;
flag = false;
} else {// other wise one shot to make them equal
sum += cur;
flag = true;
}
}
if (flag) {
++ans;
}
cout << ans << '\n';
return ;
}