2020 China Collegiate Programming Contest Mianyang Site
#include <bits/stdc++.h>
#define int ll
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
const int mod=998244353;
int a[maxn];
int t=0;
int n;
bool check(int x){
int res=x;
for(int i=1;i<=n;i++){
if(a[i]>=x) continue;
res-=x-a[i];
if(res<=0) break;
}
return res>0;
}
void solve() {
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i],++a[i];
int l=0,r=1e18;
while (l<r){
int mid = (r + l + 1) >> 1;
if(check(mid)) l=mid;
else r=mid-1;
}
cout<<"Case #"<<t<<": "<<l<<"\n";
}
signed main() {
int _ = 1;
cin >> _;
while (_--) {
t++;
solve();
}
return 0;
}
7-11 Knowledge is Power
#include <bits/stdc++.h>
#define int ll
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
const int mod=998244353;
int t=0;
int gcd(int a,int b){
return b==0?a:gcd(b,a%b);
}
void solve() {
int x,res;
cin>>x;
if(x&1) res=1;
else if(x==6) res=-1;
else{
int tx=x/2;
if(!(tx&1)) res=2;
else{
res=4;
if(x%3==0) res=min(res,2ll);
int tmp=x-4;
if(tmp%3==0&&(tmp/3)%2==0&&tmp/3>1){
int a=tmp/3,b=a+1,c=a+3;
if(gcd(a, b) == 1 && gcd(a, c) == 1 && gcd(b, c) == 1) res = min(res, 3ll);
}
--tmp;
if(tmp%3==0&&(tmp/3)%2&&tmp/3>1){
int a=tmp/3,b=a+2,c=a+3;
if(gcd(a, b) == 1 && gcd(a, c) == 1 && gcd(b, c) == 1) res = min(res, 3ll);
}
}
}
printf("Case #%d: %d\n", t, res);
}
signed main() {
int _ = 1;
cin >> _;
while (_--) {
t++;
solve();
}
return 0;
}
7-10 Joy of Handcraft
#include <bits/stdc++.h>
#define int ll
using namespace std;
typedef long long ll;
const int mod = 998244353;
const int maxn = 1e5 + 10;
int tree[maxn * 4];
int lazy[maxn * 4];
int ca = 0;
struct node {
int t, x;
} a[maxn], b[maxn];
void init() {
ca++;
memset(tree, 0, sizeof(tree));
memset(lazy, 0, sizeof(lazy));
}
bool cmp(node a, node b) {
if (a.t == b.t) return a.x > b.x;
return a.t < b.t;
}
void pushdown(int t) {
lazy[t << 1] = max(lazy[t], lazy[t << 1]);
lazy[t << 1 | 1] = max(lazy[t], lazy[t << 1 | 1]);
tree[t << 1] = max(lazy[t << 1], tree[t << 1]);
tree[t << 1|1] = max(lazy[t << 1 | 1], tree[t << 1 | 1]);
}
int query(int l, int r, int t, int L, int R) {
if (l >= L && r <= R) return tree[t];
if (l > R || r < L) return 0;
int mid = (l + r) >> 1;
int d = 0;
pushdown(t);
if (mid >= L) d = max(d, query(l, mid, t << 1, L, R));
if (mid < R) d = max(d, query(mid + 1, r, t << 1 | 1, L, R));
return d;
}
void update(int l, int r, int t, int L, int R, int d) {
if (l >= L && r <= R) lazy[t] = max(lazy[t], d), tree[t] = max(tree[t], lazy[t]);
else {
pushdown(t);
int mid = (l + r) >> 1;
if (mid >= L)update(l, mid, t << 1, L, R, d);
if (mid < R) update(mid + 1, r, t << 1 | 1, L, R, d);
}
}
void solve() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; ++i) cin >> b[i].t >> b[i].x;
sort(b + 1, b + n + 1, cmp);
int top = 1;
a[1] = b[1];
for (int i = 2; i <= n; ++i)
if (b[i].t != a[top].t)
a[++top] = b[i];
for (int i = 1; i <= top; ++i) {
for (int k = 0;; ++k) {
int l = 2 * k * a[i].t + 1;
int r = min(l - 1 + a[i].t, m);
if (l <= m && r <= m) update(1, m, 1, l, r, a[i].x);
if (l >= m || r >= m) break;
}
};
printf("Case #%d:", ca);
for (int i = 1; i <= m; ++i)
cout << " " << query(1, m, 1, i, i);
cout << "\n";
}
signed main() {
int _ = 1;
cin >> _;
while (_--) {
init();
solve();
}
return 0;
}