/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 536.0 KiB
#2 Wrong Answer 1ms 536.0 KiB
#3 Wrong Answer 67ms 9.711 MiB
#4 Wrong Answer 63ms 9.918 MiB
#5 Accepted 52ms 9.773 MiB
#6 Wrong Answer 60ms 9.77 MiB
#7 Wrong Answer 829ms 59.52 MiB
#8 Wrong Answer 809ms 59.566 MiB
#9 Wrong Answer 807ms 59.562 MiB
#10 Wrong Answer 809ms 59.562 MiB
#11 Wrong Answer 798ms 59.52 MiB
#12 Wrong Answer 798ms 59.52 MiB
#13 Wrong Answer 798ms 59.52 MiB
#14 Accepted 443ms 64.566 MiB
#15 Accepted 452ms 64.562 MiB
#16 Accepted 440ms 64.52 MiB

Code

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
using namespace std;
using namespace __gnu_pbds;
const ll md=1e9+7;
const ll smpl=4*1e5;
const ll p=31;


void dfs(int i,int vis[],int ara[],int &j,map<int,vector<int>>&tree){
vis[i]++;
ara[j]=i;
j++;
for(auto it:tree[i]){
    if(!vis[it]){
        dfs(it,vis,ara,j,tree);
    }
}
ara[j]=i;
j++;


}
void fxd(int i,int j,int ara[],int ara1[],int seg[],int node){

if(i==j){
    if(ara[ara1[i]]==1)seg[node]=1;
    else seg[node]=0;
    return;
}
int mid=(i+j)/2;
fxd(i,mid,ara,ara1,seg,node*2);
fxd(mid+1,j,ara,ara1,seg,node*2+1);
seg[node]=seg[node*2]+seg[node*2+1];
}
void updt(int i,int j,int l,int r,int seg[],int seg1[],int node){
if(i>r||j<l)return;
if(i>=l&&j<=r){
    seg[node]=(j-i+1)-seg[node];
    seg1[node]++;
    return;
}
int mid=(i+j)/2;
updt(i,mid,l,r,seg,seg1,node*2);
updt(mid+1,j,l,r,seg,seg1,node*2+1);
seg[node]=seg[node*2]+seg[node*2+1];
}
ll fnd(int i,int j,int l,int  r,int seg[],int seg1[],int node,int c){

if(i>r||j<l)return 0;
if(i>=l&&j<=r){
    if(c%2==0)return seg[node];
    return (j-i+1)-seg[node];
}
int mid=(i+j)/2;
return fnd(i,mid,l,r,seg,seg1,node*2,c+seg1[node])+fnd(mid+1,j,l,r,seg,seg1,node*2+1,c+seg1[node]);

}
void sufi() {
    map<int,vector<int>>tree;
  int n;
  cin>>n;
 int  ara[n+1];
  for(int i=1;i<=n;i++)cin>>ara[i];
  for(int i=1;i<n;i++){
    int x,y;
    cin>>x>>y;
    tree[x].push_back(y);
    tree[y].push_back(x);
  }
 int  ara1[2*n+9];
  int vis[n+1]={0};
  int j=1;
  dfs(1,vis,ara1,j,tree);
 int seg[8*n+10];
  int seg1[8*n+10]={0};
  fxd(1,2*n,ara,ara1,seg,1);
  int q;
  cin>>q;
  map<int,vector<int>>mp;
  for(int i=1;i<=2*n;i++)mp[ara1[i]].push_back(i);
  while(q--){
    int k;
    cin>>k;
    if(k==1){
        int x;
        cin>>x;
        updt(1,2*n,mp[x][0],mp[x][1],seg,seg1,1);
        continue;
    }
    else{
            int x;
    cin>>x;
            int c=0;
        ll tmp=fnd(1,2*n,mp[x][0],mp[x][1],seg,seg1,1,c);
    cout<<tmp/2<<endl;
    }

  }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    t=1;
    while(t--)
    sufi();
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1101 Mr. Heart and the Enchanted Lights
Language
C++17 (G++ 13.2.0)
Submit At
2024-10-04 11:09:53
Judged At
2024-10-04 11:09:53
Judged By
Score
40
Total Time
829ms
Peak Memory
64.566 MiB