답안 #849880

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
849880 2023-09-15T14:01:46 Z 1075508020060209tc Vinjete (COI22_vinjete) C++14
69 / 100
370 ms 128516 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n;int m;int M;
struct SGTR{
int rl;int rr;
int l;int r;
int mn;
int mnfq;
int lz;
}tr[500005];
vector<pair<int,int>>e[100005];//{v,eid}
int lar[100005];int rar[100005];
pair<int,int>rmp[2000006];
void pull(int nw){
if(tr[nw*2].mn<tr[nw*2+1].mn){
    tr[nw].mn=tr[nw*2].mn;
    tr[nw].mnfq=tr[nw*2].mnfq;
    return;
}
if(tr[nw*2+1].mn<tr[nw*2].mn){
    tr[nw].mn=tr[nw*2+1].mn;
    tr[nw].mnfq=tr[nw*2+1].mnfq;
    return;
}
tr[nw].mn=tr[nw*2].mn;
tr[nw].mnfq=tr[nw*2].mnfq+tr[nw*2+1].mnfq;
}

void buildtr(int nw,int l,int r){
tr[nw].l=l;tr[nw].r=r;
tr[nw].rl=rmp[l].first;tr[nw].rr=rmp[r].second;
tr[nw].mn=0;
tr[nw].lz=0;
if(l==r){
    tr[nw].mnfq=tr[nw].rr-tr[nw].rl+1;
    return;
}
int mi=(l+r)/2;
buildtr(nw*2,l,mi);buildtr(nw*2+1,mi+1,r);
pull(nw);
}

void psh(int nw){
tr[nw*2].mn+=tr[nw].lz;
tr[nw*2+1].mn+=tr[nw].lz;
tr[nw*2].lz+=tr[nw].lz;
tr[nw*2+1].lz+=tr[nw].lz;
tr[nw].lz=0;
}

void upd(int nw,int rl,int rr,int v){
if(tr[nw].rl>=rl&&tr[nw].rr<=rr){
    tr[nw].lz+=v;
    tr[nw].mn+=v;
   // cout<<"hehe";
    //cout<<nw<<" "<<tr[nw].rl<<" "<<tr[nw].rr<<" "<<tr[nw].mn<<" "<<tr[nw].mnfq<<" "<<tr[nw].lz<<endl;
    return;
}
if(tr[nw].rl>rr||tr[nw].rr<rl){return;}
psh(nw);
upd(nw*2,rl,rr,v);upd(nw*2+1,rl,rr,v);
pull(nw);
}
int totlen;
void lisanhua(){
set<pair<int,int>>st;
set<int>stt;
for(int i=1;i<=n-1;i++){
    st.insert({lar[i],lar[i]});
    st.insert({rar[i],rar[i]});
    stt.insert(lar[i]);
    stt.insert(rar[i]);
}
for(auto it=stt.begin();it!=stt.end();it++){
    if(next(it)!=stt.end()){
        int v=(*it);
        int vv=(*next(it));
        if(vv-v>=2){
            st.insert({v+1,vv-1});
        }
    }
}
m=0;
for(auto it=st.begin();it!=st.end();it++){
    int l=(*it).first;int r=(*it).second;
    rmp[++m]={l,r};
   // cout<<l<<" "<<r<<endl;
}
totlen=rmp[m].second-rmp[1].first+1;
}
int fans[200005];

void dfs(int nw,int pa){
if(tr[1].mn==0){
    fans[nw]=totlen-tr[1].mnfq;
}else{
    fans[nw]=totlen;
}
for(int i=0;i<e[nw].size();i++){
    int v=e[nw][i].first;
    if(v==pa){continue;}
    int id=e[nw][i].second;
    upd(1,lar[id],rar[id],1);
    dfs(v,nw);
    upd(1,lar[id],rar[id],-1);
}


}


signed main(){
cin>>n>>m;
for(int i=1;i<=n-1;i++){
    int a;int b;
    cin>>a>>b>>lar[i]>>rar[i];
    e[a].push_back({b,i});
    e[b].push_back({a,i});
}
lisanhua();
buildtr(1,1,m);
/*
upd(1,1,4,1);
cout<<tr[1].mnfq<<"\n";
for(int nw=1;nw<=24;nw++){
    cout<<nw<<" "<<tr[nw].rl<<" "<<tr[nw].rr<<" "<<tr[nw].mn<<" "<<tr[nw].mnfq<<" "<<tr[nw].lz<<endl;
}

upd(1,2,3,1);
cout<<tr[1].mnfq<<"\n";

for(int nw=1;nw<=24;nw++){
    cout<<nw<<" "<<tr[nw].rl<<" "<<tr[nw].rr<<" "<<tr[nw].mn<<" "<<tr[nw].mnfq<<" "<<tr[nw].lz<<endl;
}

return 0;
cout<<endl<<endl;*/
dfs(1,0);
for(int i=2;i<=n;i++){
    cout<<fans[i]<<"\n";
}

}

Compilation message

Main.cpp: In function 'void dfs(long long int, long long int)':
Main.cpp:100:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  100 | for(int i=0;i<e[nw].size();i++){
      |             ~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 8796 KB Output is correct
2 Correct 4 ms 8660 KB Output is correct
3 Correct 3 ms 9048 KB Output is correct
4 Correct 3 ms 8796 KB Output is correct
5 Correct 3 ms 8796 KB Output is correct
6 Correct 3 ms 8792 KB Output is correct
7 Correct 2 ms 8536 KB Output is correct
8 Correct 2 ms 8536 KB Output is correct
9 Correct 3 ms 8540 KB Output is correct
10 Correct 3 ms 8540 KB Output is correct
11 Correct 3 ms 8796 KB Output is correct
12 Correct 3 ms 8796 KB Output is correct
13 Correct 3 ms 8796 KB Output is correct
14 Correct 3 ms 8656 KB Output is correct
15 Correct 2 ms 8540 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 3 ms 8660 KB Output is correct
18 Correct 3 ms 8536 KB Output is correct
19 Correct 3 ms 8796 KB Output is correct
20 Correct 3 ms 8796 KB Output is correct
21 Correct 3 ms 8796 KB Output is correct
22 Correct 3 ms 8796 KB Output is correct
23 Correct 2 ms 8536 KB Output is correct
24 Correct 2 ms 8540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 8796 KB Output is correct
2 Correct 4 ms 8660 KB Output is correct
3 Correct 3 ms 9048 KB Output is correct
4 Correct 3 ms 8796 KB Output is correct
5 Correct 3 ms 8796 KB Output is correct
6 Correct 3 ms 8792 KB Output is correct
7 Correct 2 ms 8536 KB Output is correct
8 Correct 2 ms 8536 KB Output is correct
9 Correct 3 ms 8540 KB Output is correct
10 Correct 3 ms 8540 KB Output is correct
11 Correct 3 ms 8796 KB Output is correct
12 Correct 3 ms 8796 KB Output is correct
13 Correct 3 ms 8796 KB Output is correct
14 Correct 3 ms 8656 KB Output is correct
15 Correct 2 ms 8540 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 3 ms 8660 KB Output is correct
18 Correct 3 ms 8536 KB Output is correct
19 Correct 3 ms 8796 KB Output is correct
20 Correct 3 ms 8796 KB Output is correct
21 Correct 3 ms 8796 KB Output is correct
22 Correct 3 ms 8796 KB Output is correct
23 Correct 2 ms 8536 KB Output is correct
24 Correct 2 ms 8540 KB Output is correct
25 Correct 3 ms 8792 KB Output is correct
26 Correct 3 ms 8796 KB Output is correct
27 Correct 4 ms 11104 KB Output is correct
28 Correct 5 ms 11100 KB Output is correct
29 Correct 3 ms 8796 KB Output is correct
30 Correct 3 ms 8796 KB Output is correct
31 Correct 4 ms 10956 KB Output is correct
32 Correct 4 ms 11100 KB Output is correct
33 Correct 4 ms 11100 KB Output is correct
34 Correct 4 ms 11100 KB Output is correct
35 Correct 3 ms 8624 KB Output is correct
36 Correct 3 ms 8540 KB Output is correct
37 Correct 5 ms 11100 KB Output is correct
38 Correct 4 ms 11100 KB Output is correct
39 Correct 3 ms 8796 KB Output is correct
40 Correct 4 ms 8796 KB Output is correct
41 Correct 4 ms 11100 KB Output is correct
42 Correct 4 ms 11100 KB Output is correct
43 Correct 3 ms 8540 KB Output is correct
44 Correct 3 ms 8540 KB Output is correct
45 Correct 4 ms 11096 KB Output is correct
46 Correct 4 ms 11096 KB Output is correct
47 Correct 3 ms 8796 KB Output is correct
48 Correct 3 ms 8796 KB Output is correct
49 Correct 4 ms 11100 KB Output is correct
50 Correct 4 ms 11100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 8796 KB Output is correct
2 Correct 4 ms 8660 KB Output is correct
3 Correct 3 ms 9048 KB Output is correct
4 Correct 3 ms 8796 KB Output is correct
5 Correct 3 ms 8796 KB Output is correct
6 Correct 3 ms 8792 KB Output is correct
7 Correct 2 ms 8536 KB Output is correct
8 Correct 2 ms 8536 KB Output is correct
9 Correct 3 ms 8540 KB Output is correct
10 Correct 3 ms 8540 KB Output is correct
11 Correct 3 ms 8796 KB Output is correct
12 Correct 3 ms 8796 KB Output is correct
13 Correct 3 ms 8796 KB Output is correct
14 Correct 3 ms 8656 KB Output is correct
15 Correct 2 ms 8540 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 3 ms 8660 KB Output is correct
18 Correct 3 ms 8536 KB Output is correct
19 Correct 3 ms 8796 KB Output is correct
20 Correct 3 ms 8796 KB Output is correct
21 Correct 3 ms 8796 KB Output is correct
22 Correct 3 ms 8796 KB Output is correct
23 Correct 2 ms 8536 KB Output is correct
24 Correct 2 ms 8540 KB Output is correct
25 Correct 58 ms 14772 KB Output is correct
26 Correct 58 ms 14636 KB Output is correct
27 Correct 110 ms 26940 KB Output is correct
28 Correct 110 ms 26904 KB Output is correct
29 Correct 87 ms 26352 KB Output is correct
30 Correct 84 ms 26456 KB Output is correct
31 Correct 12 ms 14940 KB Output is correct
32 Correct 12 ms 14940 KB Output is correct
33 Correct 12 ms 14936 KB Output is correct
34 Correct 13 ms 15088 KB Output is correct
35 Correct 61 ms 12116 KB Output is correct
36 Correct 57 ms 12112 KB Output is correct
37 Correct 108 ms 24264 KB Output is correct
38 Correct 112 ms 24388 KB Output is correct
39 Correct 86 ms 23636 KB Output is correct
40 Correct 87 ms 23632 KB Output is correct
41 Correct 12 ms 14684 KB Output is correct
42 Correct 14 ms 14772 KB Output is correct
43 Correct 60 ms 11860 KB Output is correct
44 Correct 66 ms 11796 KB Output is correct
45 Correct 116 ms 23968 KB Output is correct
46 Correct 112 ms 23948 KB Output is correct
47 Correct 85 ms 23272 KB Output is correct
48 Correct 85 ms 23376 KB Output is correct
49 Correct 14 ms 14684 KB Output is correct
50 Correct 13 ms 14684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 8796 KB Output is correct
2 Correct 4 ms 8660 KB Output is correct
3 Correct 3 ms 9048 KB Output is correct
4 Correct 3 ms 8796 KB Output is correct
5 Correct 3 ms 8796 KB Output is correct
6 Correct 3 ms 8792 KB Output is correct
7 Correct 2 ms 8536 KB Output is correct
8 Correct 2 ms 8536 KB Output is correct
9 Correct 3 ms 8540 KB Output is correct
10 Correct 3 ms 8540 KB Output is correct
11 Correct 3 ms 8796 KB Output is correct
12 Correct 3 ms 8796 KB Output is correct
13 Correct 3 ms 8796 KB Output is correct
14 Correct 3 ms 8656 KB Output is correct
15 Correct 2 ms 8540 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 3 ms 8660 KB Output is correct
18 Correct 3 ms 8536 KB Output is correct
19 Correct 3 ms 8796 KB Output is correct
20 Correct 3 ms 8796 KB Output is correct
21 Correct 3 ms 8796 KB Output is correct
22 Correct 3 ms 8796 KB Output is correct
23 Correct 2 ms 8536 KB Output is correct
24 Correct 2 ms 8540 KB Output is correct
25 Correct 58 ms 14772 KB Output is correct
26 Correct 58 ms 14636 KB Output is correct
27 Correct 110 ms 26940 KB Output is correct
28 Correct 110 ms 26904 KB Output is correct
29 Correct 87 ms 26352 KB Output is correct
30 Correct 84 ms 26456 KB Output is correct
31 Correct 12 ms 14940 KB Output is correct
32 Correct 12 ms 14940 KB Output is correct
33 Correct 12 ms 14936 KB Output is correct
34 Correct 13 ms 15088 KB Output is correct
35 Correct 61 ms 12116 KB Output is correct
36 Correct 57 ms 12112 KB Output is correct
37 Correct 108 ms 24264 KB Output is correct
38 Correct 112 ms 24388 KB Output is correct
39 Correct 86 ms 23636 KB Output is correct
40 Correct 87 ms 23632 KB Output is correct
41 Correct 12 ms 14684 KB Output is correct
42 Correct 14 ms 14772 KB Output is correct
43 Correct 60 ms 11860 KB Output is correct
44 Correct 66 ms 11796 KB Output is correct
45 Correct 116 ms 23968 KB Output is correct
46 Correct 112 ms 23948 KB Output is correct
47 Correct 85 ms 23272 KB Output is correct
48 Correct 85 ms 23376 KB Output is correct
49 Correct 14 ms 14684 KB Output is correct
50 Correct 13 ms 14684 KB Output is correct
51 Correct 144 ms 23892 KB Output is correct
52 Correct 145 ms 23884 KB Output is correct
53 Correct 304 ms 50340 KB Output is correct
54 Correct 310 ms 50360 KB Output is correct
55 Correct 226 ms 48976 KB Output is correct
56 Correct 226 ms 48960 KB Output is correct
57 Correct 47 ms 27984 KB Output is correct
58 Correct 46 ms 27988 KB Output is correct
59 Correct 47 ms 27732 KB Output is correct
60 Correct 49 ms 27984 KB Output is correct
61 Correct 141 ms 17488 KB Output is correct
62 Correct 145 ms 17500 KB Output is correct
63 Correct 319 ms 43604 KB Output is correct
64 Correct 319 ms 43816 KB Output is correct
65 Correct 246 ms 42436 KB Output is correct
66 Correct 243 ms 42068 KB Output is correct
67 Correct 49 ms 26816 KB Output is correct
68 Correct 49 ms 26452 KB Output is correct
69 Correct 154 ms 16468 KB Output is correct
70 Correct 157 ms 16744 KB Output is correct
71 Correct 324 ms 43088 KB Output is correct
72 Correct 321 ms 42868 KB Output is correct
73 Correct 244 ms 41284 KB Output is correct
74 Correct 237 ms 41156 KB Output is correct
75 Correct 53 ms 26460 KB Output is correct
76 Correct 56 ms 26436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 8796 KB Output is correct
2 Correct 4 ms 8660 KB Output is correct
3 Correct 3 ms 9048 KB Output is correct
4 Correct 3 ms 8796 KB Output is correct
5 Correct 3 ms 8796 KB Output is correct
6 Correct 3 ms 8792 KB Output is correct
7 Correct 2 ms 8536 KB Output is correct
8 Correct 2 ms 8536 KB Output is correct
9 Correct 3 ms 8540 KB Output is correct
10 Correct 3 ms 8540 KB Output is correct
11 Correct 3 ms 8796 KB Output is correct
12 Correct 3 ms 8796 KB Output is correct
13 Correct 3 ms 8796 KB Output is correct
14 Correct 3 ms 8656 KB Output is correct
15 Correct 2 ms 8540 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 3 ms 8660 KB Output is correct
18 Correct 3 ms 8536 KB Output is correct
19 Correct 3 ms 8796 KB Output is correct
20 Correct 3 ms 8796 KB Output is correct
21 Correct 3 ms 8796 KB Output is correct
22 Correct 3 ms 8796 KB Output is correct
23 Correct 2 ms 8536 KB Output is correct
24 Correct 2 ms 8540 KB Output is correct
25 Correct 3 ms 8792 KB Output is correct
26 Correct 3 ms 8796 KB Output is correct
27 Correct 4 ms 11104 KB Output is correct
28 Correct 5 ms 11100 KB Output is correct
29 Correct 3 ms 8796 KB Output is correct
30 Correct 3 ms 8796 KB Output is correct
31 Correct 4 ms 10956 KB Output is correct
32 Correct 4 ms 11100 KB Output is correct
33 Correct 4 ms 11100 KB Output is correct
34 Correct 4 ms 11100 KB Output is correct
35 Correct 3 ms 8624 KB Output is correct
36 Correct 3 ms 8540 KB Output is correct
37 Correct 5 ms 11100 KB Output is correct
38 Correct 4 ms 11100 KB Output is correct
39 Correct 3 ms 8796 KB Output is correct
40 Correct 4 ms 8796 KB Output is correct
41 Correct 4 ms 11100 KB Output is correct
42 Correct 4 ms 11100 KB Output is correct
43 Correct 3 ms 8540 KB Output is correct
44 Correct 3 ms 8540 KB Output is correct
45 Correct 4 ms 11096 KB Output is correct
46 Correct 4 ms 11096 KB Output is correct
47 Correct 3 ms 8796 KB Output is correct
48 Correct 3 ms 8796 KB Output is correct
49 Correct 4 ms 11100 KB Output is correct
50 Correct 4 ms 11100 KB Output is correct
51 Correct 58 ms 14772 KB Output is correct
52 Correct 58 ms 14636 KB Output is correct
53 Correct 110 ms 26940 KB Output is correct
54 Correct 110 ms 26904 KB Output is correct
55 Correct 87 ms 26352 KB Output is correct
56 Correct 84 ms 26456 KB Output is correct
57 Correct 12 ms 14940 KB Output is correct
58 Correct 12 ms 14940 KB Output is correct
59 Correct 12 ms 14936 KB Output is correct
60 Correct 13 ms 15088 KB Output is correct
61 Correct 61 ms 12116 KB Output is correct
62 Correct 57 ms 12112 KB Output is correct
63 Correct 108 ms 24264 KB Output is correct
64 Correct 112 ms 24388 KB Output is correct
65 Correct 86 ms 23636 KB Output is correct
66 Correct 87 ms 23632 KB Output is correct
67 Correct 12 ms 14684 KB Output is correct
68 Correct 14 ms 14772 KB Output is correct
69 Correct 60 ms 11860 KB Output is correct
70 Correct 66 ms 11796 KB Output is correct
71 Correct 116 ms 23968 KB Output is correct
72 Correct 112 ms 23948 KB Output is correct
73 Correct 85 ms 23272 KB Output is correct
74 Correct 85 ms 23376 KB Output is correct
75 Correct 14 ms 14684 KB Output is correct
76 Correct 13 ms 14684 KB Output is correct
77 Correct 144 ms 23892 KB Output is correct
78 Correct 145 ms 23884 KB Output is correct
79 Correct 304 ms 50340 KB Output is correct
80 Correct 310 ms 50360 KB Output is correct
81 Correct 226 ms 48976 KB Output is correct
82 Correct 226 ms 48960 KB Output is correct
83 Correct 47 ms 27984 KB Output is correct
84 Correct 46 ms 27988 KB Output is correct
85 Correct 47 ms 27732 KB Output is correct
86 Correct 49 ms 27984 KB Output is correct
87 Correct 141 ms 17488 KB Output is correct
88 Correct 145 ms 17500 KB Output is correct
89 Correct 319 ms 43604 KB Output is correct
90 Correct 319 ms 43816 KB Output is correct
91 Correct 246 ms 42436 KB Output is correct
92 Correct 243 ms 42068 KB Output is correct
93 Correct 49 ms 26816 KB Output is correct
94 Correct 49 ms 26452 KB Output is correct
95 Correct 154 ms 16468 KB Output is correct
96 Correct 157 ms 16744 KB Output is correct
97 Correct 324 ms 43088 KB Output is correct
98 Correct 321 ms 42868 KB Output is correct
99 Correct 244 ms 41284 KB Output is correct
100 Correct 237 ms 41156 KB Output is correct
101 Correct 53 ms 26460 KB Output is correct
102 Correct 56 ms 26436 KB Output is correct
103 Correct 153 ms 24740 KB Output is correct
104 Correct 153 ms 24824 KB Output is correct
105 Runtime error 370 ms 128516 KB Execution killed with signal 11
106 Halted 0 ms 0 KB -