답안 #849884

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
849884 2023-09-15T14:04:02 Z 1075508020060209tc Vinjete (COI22_vinjete) C++14
100 / 100
552 ms 82768 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[1700005];
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(int, int)':
Main.cpp:100:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, 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 8536 KB Output is correct
2 Correct 3 ms 8536 KB Output is correct
3 Correct 3 ms 8792 KB Output is correct
4 Correct 3 ms 8792 KB Output is correct
5 Correct 3 ms 8792 KB Output is correct
6 Correct 3 ms 8792 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 2 ms 8540 KB Output is correct
9 Correct 4 ms 8536 KB Output is correct
10 Correct 3 ms 8536 KB Output is correct
11 Correct 4 ms 8536 KB Output is correct
12 Correct 3 ms 8536 KB Output is correct
13 Correct 3 ms 8540 KB Output is correct
14 Correct 3 ms 8540 KB Output is correct
15 Correct 2 ms 8536 KB Output is correct
16 Correct 1 ms 8536 KB Output is correct
17 Correct 3 ms 8536 KB Output is correct
18 Correct 3 ms 8536 KB Output is correct
19 Correct 3 ms 8536 KB Output is correct
20 Correct 3 ms 8540 KB Output is correct
21 Correct 3 ms 8536 KB Output is correct
22 Correct 3 ms 8536 KB Output is correct
23 Correct 2 ms 8536 KB Output is correct
24 Correct 2 ms 8536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 8536 KB Output is correct
2 Correct 3 ms 8536 KB Output is correct
3 Correct 3 ms 8792 KB Output is correct
4 Correct 3 ms 8792 KB Output is correct
5 Correct 3 ms 8792 KB Output is correct
6 Correct 3 ms 8792 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 2 ms 8540 KB Output is correct
9 Correct 4 ms 8536 KB Output is correct
10 Correct 3 ms 8536 KB Output is correct
11 Correct 4 ms 8536 KB Output is correct
12 Correct 3 ms 8536 KB Output is correct
13 Correct 3 ms 8540 KB Output is correct
14 Correct 3 ms 8540 KB Output is correct
15 Correct 2 ms 8536 KB Output is correct
16 Correct 1 ms 8536 KB Output is correct
17 Correct 3 ms 8536 KB Output is correct
18 Correct 3 ms 8536 KB Output is correct
19 Correct 3 ms 8536 KB Output is correct
20 Correct 3 ms 8540 KB Output is correct
21 Correct 3 ms 8536 KB Output is correct
22 Correct 3 ms 8536 KB Output is correct
23 Correct 2 ms 8536 KB Output is correct
24 Correct 2 ms 8536 KB Output is correct
25 Correct 3 ms 8792 KB Output is correct
26 Correct 3 ms 8536 KB Output is correct
27 Correct 4 ms 9048 KB Output is correct
28 Correct 4 ms 9048 KB Output is correct
29 Correct 3 ms 8796 KB Output is correct
30 Correct 3 ms 8792 KB Output is correct
31 Correct 5 ms 9048 KB Output is correct
32 Correct 4 ms 9048 KB Output is correct
33 Correct 4 ms 8796 KB Output is correct
34 Correct 3 ms 8792 KB Output is correct
35 Correct 5 ms 8536 KB Output is correct
36 Correct 3 ms 8536 KB Output is correct
37 Correct 4 ms 8796 KB Output is correct
38 Correct 5 ms 8796 KB Output is correct
39 Correct 3 ms 8796 KB Output is correct
40 Correct 3 ms 8792 KB Output is correct
41 Correct 4 ms 8792 KB Output is correct
42 Correct 4 ms 8792 KB Output is correct
43 Correct 3 ms 8536 KB Output is correct
44 Correct 3 ms 8536 KB Output is correct
45 Correct 4 ms 8796 KB Output is correct
46 Correct 4 ms 8792 KB Output is correct
47 Correct 3 ms 8792 KB Output is correct
48 Correct 3 ms 8792 KB Output is correct
49 Correct 3 ms 8796 KB Output is correct
50 Correct 4 ms 8792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 8536 KB Output is correct
2 Correct 3 ms 8536 KB Output is correct
3 Correct 3 ms 8792 KB Output is correct
4 Correct 3 ms 8792 KB Output is correct
5 Correct 3 ms 8792 KB Output is correct
6 Correct 3 ms 8792 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 2 ms 8540 KB Output is correct
9 Correct 4 ms 8536 KB Output is correct
10 Correct 3 ms 8536 KB Output is correct
11 Correct 4 ms 8536 KB Output is correct
12 Correct 3 ms 8536 KB Output is correct
13 Correct 3 ms 8540 KB Output is correct
14 Correct 3 ms 8540 KB Output is correct
15 Correct 2 ms 8536 KB Output is correct
16 Correct 1 ms 8536 KB Output is correct
17 Correct 3 ms 8536 KB Output is correct
18 Correct 3 ms 8536 KB Output is correct
19 Correct 3 ms 8536 KB Output is correct
20 Correct 3 ms 8540 KB Output is correct
21 Correct 3 ms 8536 KB Output is correct
22 Correct 3 ms 8536 KB Output is correct
23 Correct 2 ms 8536 KB Output is correct
24 Correct 2 ms 8536 KB Output is correct
25 Correct 60 ms 13164 KB Output is correct
26 Correct 59 ms 13392 KB Output is correct
27 Correct 111 ms 20816 KB Output is correct
28 Correct 109 ms 20704 KB Output is correct
29 Correct 81 ms 20092 KB Output is correct
30 Correct 84 ms 20052 KB Output is correct
31 Correct 12 ms 12376 KB Output is correct
32 Correct 12 ms 12376 KB Output is correct
33 Correct 12 ms 12376 KB Output is correct
34 Correct 12 ms 12376 KB Output is correct
35 Correct 59 ms 10580 KB Output is correct
36 Correct 58 ms 10832 KB Output is correct
37 Correct 115 ms 18000 KB Output is correct
38 Correct 118 ms 18260 KB Output is correct
39 Correct 90 ms 17488 KB Output is correct
40 Correct 82 ms 17488 KB Output is correct
41 Correct 12 ms 12120 KB Output is correct
42 Correct 12 ms 12120 KB Output is correct
43 Correct 61 ms 10320 KB Output is correct
44 Correct 61 ms 10432 KB Output is correct
45 Correct 112 ms 17876 KB Output is correct
46 Correct 109 ms 17824 KB Output is correct
47 Correct 82 ms 17232 KB Output is correct
48 Correct 84 ms 17124 KB Output is correct
49 Correct 12 ms 12120 KB Output is correct
50 Correct 12 ms 12120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 8536 KB Output is correct
2 Correct 3 ms 8536 KB Output is correct
3 Correct 3 ms 8792 KB Output is correct
4 Correct 3 ms 8792 KB Output is correct
5 Correct 3 ms 8792 KB Output is correct
6 Correct 3 ms 8792 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 2 ms 8540 KB Output is correct
9 Correct 4 ms 8536 KB Output is correct
10 Correct 3 ms 8536 KB Output is correct
11 Correct 4 ms 8536 KB Output is correct
12 Correct 3 ms 8536 KB Output is correct
13 Correct 3 ms 8540 KB Output is correct
14 Correct 3 ms 8540 KB Output is correct
15 Correct 2 ms 8536 KB Output is correct
16 Correct 1 ms 8536 KB Output is correct
17 Correct 3 ms 8536 KB Output is correct
18 Correct 3 ms 8536 KB Output is correct
19 Correct 3 ms 8536 KB Output is correct
20 Correct 3 ms 8540 KB Output is correct
21 Correct 3 ms 8536 KB Output is correct
22 Correct 3 ms 8536 KB Output is correct
23 Correct 2 ms 8536 KB Output is correct
24 Correct 2 ms 8536 KB Output is correct
25 Correct 60 ms 13164 KB Output is correct
26 Correct 59 ms 13392 KB Output is correct
27 Correct 111 ms 20816 KB Output is correct
28 Correct 109 ms 20704 KB Output is correct
29 Correct 81 ms 20092 KB Output is correct
30 Correct 84 ms 20052 KB Output is correct
31 Correct 12 ms 12376 KB Output is correct
32 Correct 12 ms 12376 KB Output is correct
33 Correct 12 ms 12376 KB Output is correct
34 Correct 12 ms 12376 KB Output is correct
35 Correct 59 ms 10580 KB Output is correct
36 Correct 58 ms 10832 KB Output is correct
37 Correct 115 ms 18000 KB Output is correct
38 Correct 118 ms 18260 KB Output is correct
39 Correct 90 ms 17488 KB Output is correct
40 Correct 82 ms 17488 KB Output is correct
41 Correct 12 ms 12120 KB Output is correct
42 Correct 12 ms 12120 KB Output is correct
43 Correct 61 ms 10320 KB Output is correct
44 Correct 61 ms 10432 KB Output is correct
45 Correct 112 ms 17876 KB Output is correct
46 Correct 109 ms 17824 KB Output is correct
47 Correct 82 ms 17232 KB Output is correct
48 Correct 84 ms 17124 KB Output is correct
49 Correct 12 ms 12120 KB Output is correct
50 Correct 12 ms 12120 KB Output is correct
51 Correct 153 ms 20304 KB Output is correct
52 Correct 144 ms 20404 KB Output is correct
53 Correct 309 ms 35152 KB Output is correct
54 Correct 291 ms 34720 KB Output is correct
55 Correct 221 ms 33360 KB Output is correct
56 Correct 219 ms 33360 KB Output is correct
57 Correct 56 ms 20304 KB Output is correct
58 Correct 47 ms 19792 KB Output is correct
59 Correct 46 ms 19900 KB Output is correct
60 Correct 46 ms 19800 KB Output is correct
61 Correct 141 ms 13904 KB Output is correct
62 Correct 143 ms 14164 KB Output is correct
63 Correct 309 ms 28012 KB Output is correct
64 Correct 294 ms 28240 KB Output is correct
65 Correct 217 ms 26960 KB Output is correct
66 Correct 217 ms 26668 KB Output is correct
67 Correct 49 ms 18484 KB Output is correct
68 Correct 48 ms 18512 KB Output is correct
69 Correct 150 ms 13016 KB Output is correct
70 Correct 153 ms 13140 KB Output is correct
71 Correct 308 ms 27472 KB Output is correct
72 Correct 308 ms 27472 KB Output is correct
73 Correct 235 ms 25932 KB Output is correct
74 Correct 241 ms 25968 KB Output is correct
75 Correct 49 ms 18256 KB Output is correct
76 Correct 53 ms 18256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 8536 KB Output is correct
2 Correct 3 ms 8536 KB Output is correct
3 Correct 3 ms 8792 KB Output is correct
4 Correct 3 ms 8792 KB Output is correct
5 Correct 3 ms 8792 KB Output is correct
6 Correct 3 ms 8792 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 2 ms 8540 KB Output is correct
9 Correct 4 ms 8536 KB Output is correct
10 Correct 3 ms 8536 KB Output is correct
11 Correct 4 ms 8536 KB Output is correct
12 Correct 3 ms 8536 KB Output is correct
13 Correct 3 ms 8540 KB Output is correct
14 Correct 3 ms 8540 KB Output is correct
15 Correct 2 ms 8536 KB Output is correct
16 Correct 1 ms 8536 KB Output is correct
17 Correct 3 ms 8536 KB Output is correct
18 Correct 3 ms 8536 KB Output is correct
19 Correct 3 ms 8536 KB Output is correct
20 Correct 3 ms 8540 KB Output is correct
21 Correct 3 ms 8536 KB Output is correct
22 Correct 3 ms 8536 KB Output is correct
23 Correct 2 ms 8536 KB Output is correct
24 Correct 2 ms 8536 KB Output is correct
25 Correct 3 ms 8792 KB Output is correct
26 Correct 3 ms 8536 KB Output is correct
27 Correct 4 ms 9048 KB Output is correct
28 Correct 4 ms 9048 KB Output is correct
29 Correct 3 ms 8796 KB Output is correct
30 Correct 3 ms 8792 KB Output is correct
31 Correct 5 ms 9048 KB Output is correct
32 Correct 4 ms 9048 KB Output is correct
33 Correct 4 ms 8796 KB Output is correct
34 Correct 3 ms 8792 KB Output is correct
35 Correct 5 ms 8536 KB Output is correct
36 Correct 3 ms 8536 KB Output is correct
37 Correct 4 ms 8796 KB Output is correct
38 Correct 5 ms 8796 KB Output is correct
39 Correct 3 ms 8796 KB Output is correct
40 Correct 3 ms 8792 KB Output is correct
41 Correct 4 ms 8792 KB Output is correct
42 Correct 4 ms 8792 KB Output is correct
43 Correct 3 ms 8536 KB Output is correct
44 Correct 3 ms 8536 KB Output is correct
45 Correct 4 ms 8796 KB Output is correct
46 Correct 4 ms 8792 KB Output is correct
47 Correct 3 ms 8792 KB Output is correct
48 Correct 3 ms 8792 KB Output is correct
49 Correct 3 ms 8796 KB Output is correct
50 Correct 4 ms 8792 KB Output is correct
51 Correct 60 ms 13164 KB Output is correct
52 Correct 59 ms 13392 KB Output is correct
53 Correct 111 ms 20816 KB Output is correct
54 Correct 109 ms 20704 KB Output is correct
55 Correct 81 ms 20092 KB Output is correct
56 Correct 84 ms 20052 KB Output is correct
57 Correct 12 ms 12376 KB Output is correct
58 Correct 12 ms 12376 KB Output is correct
59 Correct 12 ms 12376 KB Output is correct
60 Correct 12 ms 12376 KB Output is correct
61 Correct 59 ms 10580 KB Output is correct
62 Correct 58 ms 10832 KB Output is correct
63 Correct 115 ms 18000 KB Output is correct
64 Correct 118 ms 18260 KB Output is correct
65 Correct 90 ms 17488 KB Output is correct
66 Correct 82 ms 17488 KB Output is correct
67 Correct 12 ms 12120 KB Output is correct
68 Correct 12 ms 12120 KB Output is correct
69 Correct 61 ms 10320 KB Output is correct
70 Correct 61 ms 10432 KB Output is correct
71 Correct 112 ms 17876 KB Output is correct
72 Correct 109 ms 17824 KB Output is correct
73 Correct 82 ms 17232 KB Output is correct
74 Correct 84 ms 17124 KB Output is correct
75 Correct 12 ms 12120 KB Output is correct
76 Correct 12 ms 12120 KB Output is correct
77 Correct 153 ms 20304 KB Output is correct
78 Correct 144 ms 20404 KB Output is correct
79 Correct 309 ms 35152 KB Output is correct
80 Correct 291 ms 34720 KB Output is correct
81 Correct 221 ms 33360 KB Output is correct
82 Correct 219 ms 33360 KB Output is correct
83 Correct 56 ms 20304 KB Output is correct
84 Correct 47 ms 19792 KB Output is correct
85 Correct 46 ms 19900 KB Output is correct
86 Correct 46 ms 19800 KB Output is correct
87 Correct 141 ms 13904 KB Output is correct
88 Correct 143 ms 14164 KB Output is correct
89 Correct 309 ms 28012 KB Output is correct
90 Correct 294 ms 28240 KB Output is correct
91 Correct 217 ms 26960 KB Output is correct
92 Correct 217 ms 26668 KB Output is correct
93 Correct 49 ms 18484 KB Output is correct
94 Correct 48 ms 18512 KB Output is correct
95 Correct 150 ms 13016 KB Output is correct
96 Correct 153 ms 13140 KB Output is correct
97 Correct 308 ms 27472 KB Output is correct
98 Correct 308 ms 27472 KB Output is correct
99 Correct 235 ms 25932 KB Output is correct
100 Correct 241 ms 25968 KB Output is correct
101 Correct 49 ms 18256 KB Output is correct
102 Correct 53 ms 18256 KB Output is correct
103 Correct 153 ms 20640 KB Output is correct
104 Correct 160 ms 20892 KB Output is correct
105 Correct 509 ms 79696 KB Output is correct
106 Correct 510 ms 82768 KB Output is correct
107 Correct 289 ms 53888 KB Output is correct
108 Correct 291 ms 53812 KB Output is correct
109 Correct 66 ms 23228 KB Output is correct
110 Correct 53 ms 23376 KB Output is correct
111 Correct 65 ms 23244 KB Output is correct
112 Correct 54 ms 23380 KB Output is correct
113 Correct 152 ms 16976 KB Output is correct
114 Correct 162 ms 16976 KB Output is correct
115 Correct 514 ms 76168 KB Output is correct
116 Correct 513 ms 76368 KB Output is correct
117 Correct 301 ms 47440 KB Output is correct
118 Correct 297 ms 47016 KB Output is correct
119 Correct 55 ms 22096 KB Output is correct
120 Correct 54 ms 22024 KB Output is correct
121 Correct 171 ms 16308 KB Output is correct
122 Correct 169 ms 15952 KB Output is correct
123 Correct 550 ms 75620 KB Output is correct
124 Correct 552 ms 75856 KB Output is correct
125 Correct 297 ms 46416 KB Output is correct
126 Correct 291 ms 46416 KB Output is correct
127 Correct 54 ms 21844 KB Output is correct
128 Correct 55 ms 21840 KB Output is correct