190524--牛客OI周赛10-提高组
指路:https://ac.nowcoder.com/acm/contest/900#question
A:风雨无阻(签到题)
https://ac.nowcoder.com/acm/contest/view-submission?submissionId=40697398
#include<bits/stdc++.h>
using namespace std;
const int MAXN=6e5+5;
#define ll long long
ll n;
char s[MAXN];
int main(){
scanf("%lld",&n);
scanf("%s",s);
int len=strlen(s),tmp=0;
char op=0;
for(int i=0;i<len;i++){
if(s[i]<'0'||s[i]>'9') op=s[i],tmp=0;
else tmp=tmp*10+s[i]-'0';
if(s[i+1]<'0'||s[i+1]>'9'){
if(op=='+') n+=tmp;
else if(op=='-') n-=tmp;
else if(op=='*') n*=tmp;
else if(op=='%') n%=tmp;
else n*=n;
}
}
cout<<abs(n)<<"\n";
return 0;
}
B:Taeyeon的困惑
思路参考:https://blog.csdn.net/xuxiayang/article/details/90523848以及
https://www.cnblogs.com/y2823774827y/p/10921242.html
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
multiset<int> s, r;
int a[N];
int main() {
int n, m, k; scanf("%d%d%d", &n, &m, &k);
long long sum = 0, ans = 0;
for(int i = 1; i <= n; i++) {
int x; scanf("%d", &x);
a[i] = x;
sum += x;
s.insert(x);
if(s.size() > k) {
int t = *s.rbegin();
sum -= t;
r.insert(t);
s.erase(s.find(t));
}
if(i > m) {
auto it = r.lower_bound(a[i - m]);
if(it != r.end() && *it == a[i - m]) r.erase(it);
else {
it = s.lower_bound(a[i - m]);
sum -= a[i - m];
s.erase(it);
s.insert(*r.begin());
sum += *r.begin();
r.erase(r.begin());
}
}
if(i >= m) ans += sum;
}
printf("%lld\n", ans);
return 0;
}
其他不看了,太菜了