QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#350022#6805. Data StructurejthisWA 4975ms63076kbC++144.0kb2024-03-10 12:37:292024-03-10 12:37:30

Judging History

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

  • [2024-03-10 12:37:30]
  • 评测
  • 测评结果:WA
  • 用时:4975ms
  • 内存:63076kb
  • [2024-03-10 12:37:29]
  • 提交

answer

#include <iostream>
#include <vector>
#include <vector>
#include <set>
#include "map"
#include <array>
#include <algorithm>
#include <random>
#include <bitset>
#include <chrono>
using namespace std;
#define all(x)x.begin(),x.end()
#define pack(x)sort(all(x));x.erase(unique(all(x)),x.end())
#define gi(x,v)lower_bound(all(x),v)-x.begin()
using ll=long long;
using ld=long double;
using tu=array<ll,5>;
vector<int> v[300'010];
const int sq=550;
struct seg{
    int* tree;
    int N;
    void init(int n){
        N=n;
        if(N==0)return;
        tree=new int[N+1];
    }void clear(){
        if(N==0)return;
        N=0;
        delete[] tree;
    }
    
    int query(int i) {
        i++;
        int sum = 0;
        while (i > 0) {
            sum += tree[i];
            i -= i&-i;
        }
        return sum;
    }void update(int i, ll diff) {
        while (i <= N) {
            tree[i] += diff;
            i += i&-i;
        }
    }
    
    void update(int i, int j, int diff) {
        i++;j++;
        update(i, diff);
        update(j+1, -diff);
    }
}dep[300'010];
vector<seg> line[sq+10];
///node = y mod x
vector<vector<int>> vl[sq+10];
vector<int> vd[300'010];
int deps[300'010];
int in[300'010],out[300'010],pv;
int D;
void dfs(int n,int p,int d){
    in[n]=++pv;
    deps[n]=d;D=max(D,d+1);
    vd[d].push_back(pv);
    for(auto i:v[n]){
        if(i==p)continue;
        dfs(i,n,d+1);
    }out[n]=pv;
}
vector<tu> quer;
void solve(){
    int n,m;quer.clear();
    cin>>n>>m;
    D=0;
    int a,b,c,d,f;
    for(int i=2;i<=n;i++){
        cin>>a;
        v[a].push_back(i);
    }
    pv=0;
    dfs(1,0,1);
    
    for(int j=0;j<m;j++){
        cin>>a>>b;
        if(a==1){
            int s=in[b];
            int e=out[b];
            cin>>c>>d>>f;
            quer.push_back({a,b,c,d,f});
            if(c<=sq){
                d+=deps[b];
                d%=c;
                vl[c][d].push_back(s);
                vl[c][d].push_back(e+1);
            }
        }else{
            quer.push_back({a,b});
        }
    }
    for(int i=1;i<=sq;i++){
        for(int j=0;j<i;j++){
            if(vl[i][j].empty())continue;
            line[i][j].init(vl[i][j].size());
            pack(vl[i][j]);////정렬 - 해결
        }
    }for(int i=1;i<=D;i++){
        dep[i].init(vd[i].size());
    }
    for(int j=0;j<m;j++){
        a=quer[j][0];
        b=quer[j][1];
        c=quer[j][2];
        d=quer[j][3];
        f=quer[j][4];
        if(a==1){
            int s=in[b];
            int e=out[b];
            ///node = d mod c -> add f
            if(c<=sq){
                d+=deps[b];
                d%=c;
                int sv=gi(vl[c][d],s);
                int ev=gi(vl[c][d],e+1)-1;
                line[c][d].update(sv,ev,f);
            }else{
                for(int i=deps[b]+d;i<=D;i+=c){
                    int sv=gi(vd[i],s);
                    int ev=gi(vd[i],e+1)-1;
                    dep[i].update(sv,ev,f);
                }
            }
        }else{
            int dx=deps[b];
            int idx=in[b];
            int ans=dep[dx].query(gi(vd[dx],idx));
            for(int i=1;i<=sq;i++){
                int p=dx%i;
                ans+=line[i][p].query(gi(vl[i][p],idx+1)-1);
            }cout<<ans<<'\n';
        }
    }
    
    
    for(int i=1;i<=sq;i++){
        for(int j=0;j<i;j++){
            line[i][j].clear();
            vl[i][j].clear();
            vl[i][j].shrink_to_fit();
        }
    }
    for(int i=1;i<=n;i++){
        dep[i].clear();
        vd[i].clear();
        vd[i].shrink_to_fit();
        v[i].clear();
        v[i].shrink_to_fit();
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int tc;
    cin>>tc;
    for(int i=1;i<=sq;i++){
        line[i].resize(i);
        line[i].shrink_to_fit();
        vl[i].resize(i);
        vl[i].shrink_to_fit();
    }
    while(tc--){
        solve();
    }
 
}

詳細信息

Test #1:

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

input:

1
5 5
1 1 2 1
1 1 5 4 1
1 1 4 1 5
1 2 1 0 4
2 3
2 1

output:

5
0

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 4975ms
memory: 63076kb

input:

4
300000 300000
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98...

output:

608231
610439
611751
608989
611276
614504
615692
620406
622203
622590
-913672030
629273
638370
213062978
636514
638878
638471
643723
213490390
645098
647672
654620
653998
656783
655279
658016
658809
668692
672495
1339898136
653860
679555
-1828277850
681801
683584
683625
-1828278323
685311
688364
213...

result:

wrong answer 1st lines differ - expected: '1130', found: '608231'