T1 没写
T2 Omkar and Landslide
C++#include<bits/stdc++.h>
using namespace std;
using ll=long long;
ll n,a[1145140];
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n;
ll sum=0;
for(int i=1;i<=n;i++){
cin>>a[i];
sum+=a[i];
sum-=i;
}
ll x=sum/n,r=sum%n;
for(int i=1;i<=r;i++){
a[i]=x+1;
}
for(int i=r+1;i<=n;i++){
a[i]=x;
}
for(int i=1;i<=n;i++){
cout<<a[i]+i<<' ';
}
return 0;
}
T3 BZOJ3517 翻硬币
C++#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=1145;
ll n;
ll h[N],l[N];
char a[N][N];
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
cin>>a[i][j];
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
h[i]^=(a[i][j]-'0');
l[j]^=(a[i][j]-'0');
}
}
ll ans1=0,ans2=0;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
ans1+=h[i]^l[j]^(a[i][j]-'0');
ans2+=h[i]^l[j]^(a[i][j]-'0')^1;
}
}
cout<<min(ans1,ans2);
return 0;
}
T4 灵能传输
C++#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=114514*3;
ll n,a[N];
void solve(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
a[i]=a[i-1]+a[i];
}
sort(a+1,a+n);
ll ans=-1;
ll L=0,R=a[n];if(L>R) swap(L,R);
ll m=lower_bound(a+1,a+n,L)-a;
ll l=L,r=a[m];
for(int i=m;i;i--){
if(l<r) swap(l,r);
ans=max(ans,l-a[i]);
l=a[i];
}
ans=max(ans,abs(l-r));
l=a[m],r=R;
for(int i=m+1;i<n;i++){
if(l>r) swap(l,r);
ans=max(ans,a[i]-l);
l=a[i];
}
ans=max(ans,abs(l-r));
if(m==n) ans=max(ans,R-a[n-1]);
cout<<ans<<'\n';
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll T;
cin>>T;
while(T--) solve();
return 0;
}
T5 没写
T6 Work Scheduling G
C++#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=114514;
ll n;
priority_queue<ll,vector<ll>,greater<ll>>q;
struct Node{
ll d,w;
}a[N];
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i].d>>a[i].w;
}
sort(a+1,a+1+n,[](const Node &a,const Node &b){
return a.d<b.d||(a.d==b.d&&a.w>b.w);
});
ll ans=0,t=0;
for(int i=1;i<=n;i++){
if(t<a[i].d){
t++;
ans+=a[i].w;
q.push(a[i].w);
}else if(a[i].w>q.top()){
ans-=q.top();
ans+=a[i].w;
q.pop();
q.push(a[i].w);
}
}
cout<<ans;
return 0;
}
T7 T8 T9 没写
T10 皇后游戏
C++#include<bits/stdc++.h>
using namespace std;
using ll=long long;
struct Node{
ll x,y,d;
}a[20005];
bool operator <(const Node &a,const Node &b){
if (a.d!=b.d) return a.d<b.d;
if (a.d<=0) return a.x<b.x;
return a.y>b.y;
}
ll n,c[20005];
void solve(){
cin>>n;
for (int i=1;i<=n;i++){
cin>>a[i].x>>a[i].y;
if (a[i].x>a[i].y) a[i].d=1;
else if (a[i].x<a[i].y) a[i].d=-1;
else a[i].d=0;
}
sort(a+1,a+n+1);
ll s=0;
for (int i=1;i<=n;i++){
s+=a[i].x;
c[i]=max(c[i-1],s)+a[i].y;
}
cout<<c[n]<<'\n';
}
int main(){
ll T;
cin>>T;
while(T--) solve();
}
T11 Cow Coupons G
C++#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=51419;
ll n,k,m,ans;
struct Node{
ll p,c,i;
}a[N];
bitset<N>vis;
priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>>qp,qc;
priority_queue<ll,vector<ll>,greater<ll>> qd;
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n>>k>>m;
for(int i=1;i<=n;i++){
cin>>a[i].p>>a[i].c;
a[i].i=i;
qp.push({a[i].p,i});
qc.push({a[i].c,i});
if(i<=k) qd.push(0);
}
while(!qp.empty()){
while(!qp.empty()&&vis[qp.top().second]) qp.pop();
while(!qc.empty()&&vis[qc.top().second]) qc.pop();
if(qp.empty()) break;
auto tp=qp.top(),tc=qc.top();
if(!qd.empty()&&qd.top()>tp.first-tc.first){
m-=tp.first;
vis[tp.second]=1;
qp.pop();
}else{
m-=tc.first+qd.top();
qd.pop();
vis[tc.second]=1;
qd.push(a[tc.second].p-a[tc.second].c);
qc.pop();
}
if(m>=0) ans++;
else break;
}
cout<<ans;
return 0;
}
T12 T13 没写
T14 哈希冲突
C++#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=114514+51419;
ll a[N],biao[405][405];
ll n,m;
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n>>m;
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=1;i<=n;i++){
for(int j=1;j<=sqrt(n);j++){
biao[j][i%j]+=a[i];
}
}
for(int i=1;i<=m;i++){
char op;
cin>>op;
if(op=='A'){
ll x,y;
cin>>x>>y;
if(x<=sqrt(n)) cout<<biao[x][y]<<'\n';
else{
ll ans=0;
for(int i=y;i<=n;i+=x){
ans+=a[i];
}
cout<<ans<<'\n';
}
}else{
ll x,y;
cin>>x>>y;
for(int i=1;i<=sqrt(n);i++){
biao[i][x%i]+=y-a[x];
}
a[x]=y;
}
}
return 0;
}//喵喵喵
T15 弹飞绵羊
C++#include<bits/stdc++.h>
#define ll long long
#define CoffeeCat138 ACCat
using namespace std;
const int N=200005,m=200005/sqrt(200005)+10;
ll a[N],n,st[N],ed[N],pos[N],to[N],step[N];
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n;
ll k=sqrt(n);
for(int i=1;i<=n;i++){
cin>>a[i];
pos[i]=(i-1)/k+1;
}
ll t=n/k;
if(n%k) t++;
for(int i=1;i<=t;i++){
st[i]=(i-1)*k+1;
ed[i]=i*k;
}
ed[t]=n;
for(int i = t; i >= 1; i--){
for(int j = ed[i]; j >= st[i]; j--){
ll tmp = j + a[j];
if(tmp > ed[i]){ // 跳出当前块
to[j] = tmp;
step[j] = 1;
}else{ // 还在当前块内
to[j] = to[tmp];
step[j] = step[tmp] + 1;
}
}
}
ll q;
cin >> q;
while(q--){
ll op, x;
cin >> op >> x;
x++; // 转换为1-based索引
if(op == 1){ // 查询操作
ll ans = 0;
while(x <= n){
ans += step[x];
x = to[x];
}
cout << ans << '\n';
}else{ // 修改操作
ll newk;
cin >> newk;
a[x] = newk;
// 重新计算整个块(从后往前)
ll block = pos[x];
ll l = st[block], r = ed[block];
for(int i = r; i >= l; i--){
ll tmp = i + a[i];
if(tmp > r){ // 跳出当前块
to[i] = tmp;
step[i] = 1;
}else{ // 还在当前块内
to[i] = to[tmp];
step[i] = step[tmp] + 1;
}
}
}
}
return 0;
}
T16 T17 没写