QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#560527#859. Civilizationsrotcar07WA 203ms18844kbC++202.9kb2024-09-12 16:11:352024-09-12 16:11:36

Judging History

你现在查看的是最新测评结果

  • [2024-09-12 16:11:36]
  • 评测
  • 测评结果:WA
  • 用时:203ms
  • 内存:18844kb
  • [2024-09-12 16:11:35]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int w[505][505],p[505][505];
int n,q;
int sum[250005],l[250005],cnt[250005];
multiset<int> sb[250005];
typedef long long ll;
inline void solve(){
    cin>>n;
    for(int i=1;i<=n;i++)for(int j=1;j<=n;j++) cin>>w[i][j];
    for(int i=1;i<=n;i++)for(int j=1;j<=n;j++) cin>>p[i][j],p[i][j]++;
    for(int i=1;i<=n*n;i++) sum[i]=l[i]=cnt[i]=0,sb[i].clear();
    for(int i=1;i<=n;i++)for(int j=1;j<=n;j++){
        sum[p[i][j]]+=w[i][j];cnt[p[i][j]]++;
        if(i<n)
            if(p[i][j]!=p[i+1][j]) l[p[i][j]]++,l[p[i+1][j]]++;
        if(j<n)
            if(p[i][j]!=p[i][j+1]) l[p[i][j]]++,l[p[i][j+1]]++;
    }cin>>q;
    unordered_set<int> v;
    for(int i=1;i<=n*n;i++)if(cnt[i])v.insert(l[i]),sb[l[i]].insert(sum[i]);
    while(q--){
        int x,y,z;ll A,B,C;cin>>x>>y>>z>>A>>B>>C;z++;
        auto del=[&](int z){
            int a=l[z],b=sum[z];
            if(!cnt[z]) return;
            // cout<<"DEL "<<z<<' '<<a<<' '<<b<<'\n';
            sb[a].erase(sb[a].lower_bound(b));
            if(sb[a].empty()) v.erase(a);
        };
        auto add=[&](int z){
            int a=l[z],b=sum[z];
            if(!cnt[z]) return;
            // cout<<"ADD "<<z<<' '<<a<<' '<<b<<'\n';
            sb[a].insert(b);
            if(sb[a].size()==1) 
            assert(!v.count(a)),v.insert(a);
        };
        if(z!=p[x][y]){
            int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
            int w=p[x][y];
            for(int d=0;d<4;d++){
                int xx=x+dx[d],yy=y+dy[d];
                if(xx<1||yy<1||xx>n||yy>n) continue;
                del(p[xx][yy]);
                if(w!=p[xx][yy])l[p[xx][yy]]--;
                if(z!=p[xx][yy])l[p[xx][yy]]++;
                add(p[xx][yy]);
            }
            del(w),del(z);
            for(int d=0;d<4;d++){
                int xx=x+dx[d],yy=y+dy[d];
                if(xx<1||yy<1||xx>n||yy>n) continue;
                if(w!=p[xx][yy])l[w]--;
                if(z!=p[xx][yy])l[z]++;
            }cnt[w]--,cnt[z]++;
            sum[w]-=::w[x][y];
            add(w);
            p[x][y]=z;
            sum[z]+=::w[x][y];
            add(z);
        }
        ll ans=-1e18;
        // for(int i=1;i<=n*n;i++) cout<<i<<' '<<l[i]<<' '<<sum[i]<<' '<<cnt[i]<<'\n';
        for(auto x:v){
            ll d=A+C*x;
            // cout<<x<<' '<<sb[x].size()<<'\n';
            // for(auto z:sb[x]) cout<<z<<' ';cout<<'\n';
            assert(!sb[x].empty());
            if(d<0)ans=max(ans,B*x+d**sb[x].begin());
            else ans=max(ans,B*x+d**sb[x].rbegin());
        }
        cout<<ans<<"\n "[!!q];
    }
}
int main(){
    // string name="A";freopen((name+".in").c_str(),"r",stdin);//freopen((name+".out").c_str(),"w",stdout);
    std::ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t;cin>>t;
    while(t--) solve();
    cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 18788kb

input:

1
2
1 2
3 4
1 1
2 2
6
2 2 1 1 -1 0
1 2 2 1 2 -1
2 1 3 0 1 -1
1 2 3 2 0 0
1 1 3 1 1 1
2 2 3 -1 -1 -1

output:

5 -7 -2 10 20 -10

result:

ok 6 numbers

Test #2:

score: -100
Wrong Answer
time: 203ms
memory: 18844kb

input:

5000
13
58 69 -65 -29 -100 3 26 -29 73 -29 -93 33 73
-77 -76 69 19 -77 -61 59 -15 85 81 -20 73 72
60 -46 -100 -59 -79 -74 -94 41 -24 -28 -5 36 70
-49 -59 -11 44 26 38 -73 92 -16 -37 -84 86 90
-19 9 -30 19 -24 88 46 -80 98 -75 14 -77 55
-41 22 -71 -75 78 -97 9 -99 95 30 41 -30 72
-31 -15 14 99 -98 -1...

output:

42103747013412 35680188991650 -6713336103808 -11059164282756 -1668545181184 -8186426524853 39582599038173 38802048647760 5920723833015 -21684163594486 -16595070672095 -11701923512925 -3008229643548 -18937722770187 56407046298711 71796328172997 -6315561061725 -24088994837750 -22482313580650 545583443...

result:

wrong answer 19732nd numbers differ - expected: '388613075768', found: '414772447254'