版本比较
Day1 STD
正文
增加 187 行删除 48 行
116 行未改动全部展开11711811912012112112212312412512612712312412512612712812913013113213313413513613713813914014112812913013113213313413513613713813914014114214314414514614714814915015115215334 行未改动188189190191184185186192193194195196197198199192193194195196197200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236199200201202203204205206237238239240241242243244245246247248249250251252253254255256208209210211212257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336214337338339340341342343344345346347348349350351352353354355356357358359216217218219220360361362116 行未改动全部展开```cpp#include<bits/stdc++.h>using namespace std;using ll=long long;ll n,a[1145140];const int N=114514;ll n;priority_queue<ll,vector<ll>,greater<ll>>q;struct Node{ ll d,w;}a[N];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; 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 没写34 行未改动 while(T--) solve();}```
# T11 T12 T13 T14没写
# T15 弹飞绵羊# T11 Cow Coupons G```cpp#include<bits/stdc++.h>using namespace std;using ll=long long;const int N=51419;ll n,k,m,ans;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 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;}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;```
# T12 T13 没写
# T14 哈希冲突```cpp#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]; } 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; } 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 弹飞绵羊```cpp#include<bits/stdc++.h>#define ll long long#define CoffeeCat138 ACCatusing 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<<c[n]<<'\n'; 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;}int main(){ ll T; cin>>T; while(T--) solve();}```
# T16 T17 没写