#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define plll pair<ll,pll>
#define tull tuple<ll,ll,ll>
#define pb push_back
#define f first
#define endl '\n'
#define se second
#define piii pair<int,pii>
#define id1 id<<1
#define bit(x,i) (((x) >> (i)) & 1)
#define id2 (id<<1)+1
#define MASK(i) (1<<i)
#define set_on(x,i) ((x) | MASK(i))
#define set_off(x,i) ((x) & ~MASK(i))
#define TIME "\nTime elapsed : "<<(double)clock()/1000<<" ms"
#define all(x) x.begin(),x.end()
#define id(i,j) (i - 1) * m + j
#define TASK "test"
#define fast ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
using namespace std;
const ll mod = 1e9 + 7; //998244353;
const ll base = 311;
const ll INF = 1e18;
const ll maxn = 1e6 + 5;
const ll maxs = 1e5;
const ld pi = 3.14159265358979323846;
const ll dx[] = {-1,0,0,1};
const ll dy[] = {0,-1,1,0};
const int dx8[] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy8[] = {0, 1, 0, -1, 1, -1, 1, -1};
int n,q;
pll st[4 * maxn];
void update1(int id,int l,int r,int i,ll val)
{
if(i < l || r < i){
return;
}
if(l == r){
st[id].f = i + val;
return;
}
int mid = (l + r) >> 1;
update1(id * 2,l,mid,i,val);
update1(id * 2 + 1,mid + 1,r,i,val);
st[id].f = min(st[id * 2].f,st[id * 2 + 1].f);
}
void update2(int id,int l,int r,int i,ll val)
{
if(i < l || r < i){
return;
}
if(l == r){
st[id].se = val - i;
return;
}
int mid = (l + r) >> 1;
update2(id * 2,l,mid,i,val);
update2(id * 2 + 1,mid + 1,r,i,val);
st[id].se = min(st[id * 2].se,st[id * 2 + 1].se);
}
ll get1(int id,int l,int r,int u,int v)
{
if(v < l || r < u){
return INF;
}
if(u <= l && r <= v){
return st[id].f;
}
int mid = (l + r) >> 1;
return min(get1(id * 2,l,mid,u,v),get1(id * 2 + 1,mid + 1,r,u,v));
}
ll get2(int id,int l,int r,int u,int v)
{
if(v < l || r < u){
return INF;
}
if(u <= l && r <= v){
return st[id].se;
}
int mid = (l + r) >> 1;
return min(get2(id * 2,l,mid,u,v),get2(id * 2 + 1,mid + 1,r,u,v));
}
int main()
{
fast
cin >> n >> q;
for(int i = 1; i <= n - 1; ++i){
int u,v;
cin >> u >> v;
}
memset(st,63,sizeof(st));
while(q--){
int type;
cin >> type;
if(type == 1){
ll v,c;
cin >> v >> c;
update1(1,1,n,v,c);
update2(1,1,n,v,c);
}
else{
ll v;
cin >> v;
ll res1 = v - 1;
ll res2 = min(v - 1,get1(1,1,n,v + 1,n) - v);
ll res3 = min(v - 1,get2(1,1,n,1,v) + v);
cout << min({res1,res2,res3}) << endl;
}
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgbGwgbG9uZyBsb25nCiNkZWZpbmUgbGQgbG9uZyBkb3VibGUKI2RlZmluZSBwaWkgcGFpcjxpbnQsaW50PgojZGVmaW5lIHBsbCBwYWlyPGxsLGxsPgojZGVmaW5lIHBsbGwgcGFpcjxsbCxwbGw+CiNkZWZpbmUgdHVsbCB0dXBsZTxsbCxsbCxsbD4KI2RlZmluZSBwYiBwdXNoX2JhY2sKI2RlZmluZSBmIGZpcnN0CiNkZWZpbmUgZW5kbCAnXG4nCiNkZWZpbmUgc2Ugc2Vjb25kCiNkZWZpbmUgcGlpaSBwYWlyPGludCxwaWk+CiNkZWZpbmUgaWQxIGlkPDwxCiNkZWZpbmUgYml0KHgsaSkgKCgoeCkgPj4gKGkpKSAmIDEpCiNkZWZpbmUgaWQyIChpZDw8MSkrMQojZGVmaW5lIE1BU0soaSkgKDE8PGkpCiNkZWZpbmUgc2V0X29uKHgsaSkgKCh4KSB8IE1BU0soaSkpCiNkZWZpbmUgc2V0X29mZih4LGkpICgoeCkgJiB+TUFTSyhpKSkKI2RlZmluZSBUSU1FICJcblRpbWUgZWxhcHNlZCA6ICI8PChkb3VibGUpY2xvY2soKS8xMDAwPDwiIG1zIgoj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ArIDFdLmYpOwp9Cgp2b2lkIHVwZGF0ZTIoaW50IGlkLGludCBsLGludCByLGludCBpLGxsIHZhbCkKewogICAgaWYoaSA8IGwgfHwgciA8IGkpewogICAgICAgIHJldHVybjsKICAgIH0KCiAgICBpZihsID09IHIpewogICAgICAgIHN0W2lkXS5zZSA9IHZhbCAtIGk7CiAgICAgICAgcmV0dXJuOwogICAgfQoKICAgIGludCBtaWQgPSAobCArIHIpID4+IDE7CiAgICB1cGRhdGUyKGlkICogMixsLG1pZCxpLHZhbCk7CiAgICB1cGRhdGUyKGlkICogMiArIDEsbWlkICsgMSxyLGksdmFsKTsKCiAgICBzdFtpZF0uc2UgPSBtaW4oc3RbaWQgKiAyXS5zZSxzdFtpZCAqIDIgKyAxXS5zZSk7Cn0KCmxsIGdldDEoaW50IGlkLGludCBsLGludCByLGludCB1LGludCB2KQp7CiAgICBpZih2IDwgbCB8fCByIDwgdSl7CiAgICAgICAgcmV0dXJuIElORjsKICAgIH0KCiAgICBpZih1IDw9IGwgJiYgciA8PSB2KXsKICAgICAgICByZXR1cm4gc3RbaWRdLmY7CiAgICB9CgogICAgaW50IG1pZCA9IChsICsgcikgPj4gMTsKCiAgICByZXR1cm4gbWluKGdldDEoaWQgKiAyLGwsbWlkLHUsdiksZ2V0MShpZCAqIDIgKyAxLG1pZCArIDEscix1LHYpKTsKfQoKbGwgZ2V0MihpbnQgaWQsaW50IGwsaW50IHIsaW50IHUsaW50IHYpCnsKICAgIGlmKHYgPCBsIHx8IHIgPCB1KXsKICAgICAgICByZXR1cm4gSU5GOwogICAgfQoKICAgIGlmKHUgPD0gbCAmJiByIDw9IHYpewogICAgICAgIHJldHVybiBzdFtpZF0uc2U7CiAgICB9CgogICAgaW50IG1pZCA9IChsICsgcikgPj4gMTsKCiAgICByZXR1cm4gbWluKGdldDIoaWQgKiAyLGwsbWlkLHUsdiksZ2V0MihpZCAqIDIgKyAxLG1pZCArIDEscix1LHYpKTsKfQoKaW50IG1haW4oKQp7CiAgICBmYXN0CgogICAgY2luID4+IG4gPj4gcTsKCiAgICBmb3IoaW50IGkgPSAxOyBpIDw9IG4gLSAxOyArK2kpewogICAgICAgIGludCB1LHY7CiAgICAgICAgY2luID4+IHUgPj4gdjsKICAgIH0KCiAgICBtZW1zZXQoc3QsNjMsc2l6ZW9mKHN0KSk7CgogICAgd2hpbGUocS0tKXsKICAgICAgICBpbnQgdHlwZTsKICAgICAgICBjaW4gPj4gdHlwZTsKCiAgICAgICAgaWYodHlwZSA9PSAxKXsKICAgICAgICAgICAgbGwgdixjOwogICAgICAgICAgICBjaW4gPj4gdiA+PiBjOwogICAgICAgICAgICB1cGRhdGUxKDEsMSxuLHYsYyk7CiAgICAgICAgICAgIHVwZGF0ZTIoMSwxLG4sdixjKTsKICAgICAgICB9CiAgICAgICAgZWxzZXsKICAgICAgICAgICAgbGwgdjsKICAgICAgICAgICAgY2luID4+IHY7CgogICAgICAgICAgICBsbCByZXMxID0gdiAtIDE7CiAgICAgICAgICAgIGxsIHJlczIgPSBtaW4odiAtIDEsZ2V0MSgxLDEsbix2ICsgMSxuKSAtIHYpOwogICAgICAgICAgICBsbCByZXMzID0gbWluKHYgLSAxLGdldDIoMSwxLG4sMSx2KSArIHYpOwoKICAgICAgICAgICAgY291dCA8PCBtaW4oe3JlczEscmVzMixyZXMzfSkgPDwgZW5kbDsKICAgICAgICB9CiAgICB9CgogICAgcmV0dXJuIDA7Cn0K
Main.java:1: error: illegal character: '#'
#include <bits/stdc++.h>
^
Main.java:1: error: class, interface, or enum expected
#include <bits/stdc++.h>
^
Main.java:2: error: illegal character: '#'
#define ll long long
^
Main.java:3: error: illegal character: '#'
#define ld long double
^
Main.java:4: error: illegal character: '#'
#define pii pair<int,int>
^
Main.java:5: error: illegal character: '#'
#define pll pair<ll,ll>
^
Main.java:6: error: illegal character: '#'
#define plll pair<ll,pll>
^
Main.java:7: error: illegal character: '#'
#define tull tuple<ll,ll,ll>
^
Main.java:8: error: illegal character: '#'
#define pb push_back
^
Main.java:9: error: illegal character: '#'
#define f first
^
Main.java:10: error: illegal character: '#'
#define endl '\n'
^
Main.java:11: error: illegal character: '#'
#define se second
^
Main.java:12: error: illegal character: '#'
#define piii pair<int,pii>
^
Main.java:13: error: illegal character: '#'
#define id1 id<<1
^
Main.java:14: error: illegal character: '#'
#define bit(x,i) (((x) >> (i)) & 1)
^
Main.java:15: error: illegal character: '#'
#define id2 (id<<1)+1
^
Main.java:16: error: illegal character: '#'
#define MASK(i) (1<<i)
^
Main.java:17: error: illegal character: '#'
#define set_on(x,i) ((x) | MASK(i))
^
Main.java:18: error: illegal character: '#'
#define set_off(x,i) ((x) & ~MASK(i))
^
Main.java:19: error: illegal character: '#'
#define TIME "\nTime elapsed : "<<(double)clock()/1000<<" ms"
^
Main.java:20: error: illegal character: '#'
#define all(x) x.begin(),x.end()
^
Main.java:21: error: illegal character: '#'
#define id(i,j) (i - 1) * m + j
^
Main.java:22: error: illegal character: '#'
#define TASK "test"
^
Main.java:23: error: illegal character: '#'
#define fast ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
^
Main.java:23: error: class, interface, or enum expected
#define fast ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
^
Main.java:23: error: class, interface, or enum expected
#define fast ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
^
Main.java:24: error: class, interface, or enum expected
using namespace std;
^
Main.java:25: error: class, interface, or enum expected
const ll mod = 1e9 + 7; //998244353;
^
Main.java:26: error: class, interface, or enum expected
const ll base = 311;
^
Main.java:27: error: class, interface, or enum expected
const ll INF = 1e18;
^
Main.java:28: error: class, interface, or enum expected
const ll maxn = 1e6 + 5;
^
Main.java:29: error: class, interface, or enum expected
const ll maxs = 1e5;
^
Main.java:30: error: class, interface, or enum expected
const ld pi = 3.14159265358979323846;
^
Main.java:31: error: class, interface, or enum expected
const ll dx[] = {-1,0,0,1};
^
Main.java:32: error: class, interface, or enum expected
const ll dy[] = {0,-1,1,0};
^
Main.java:33: error: class, interface, or enum expected
const int dx8[] = {1, 0, -1, 0, 1, -1, -1, 1};
^
Main.java:34: error: class, interface, or enum expected
const int dy8[] = {0, 1, 0, -1, 1, -1, 1, -1};
^
Main.java:36: error: class, interface, or enum expected
int n,q;
^
Main.java:37: error: class, interface, or enum expected
pll st[4 * maxn];
^
Main.java:39: error: class, interface, or enum expected
void update1(int id,int l,int r,int i,ll val)
^
Main.java:43: error: class, interface, or enum expected
}
^
Main.java:47: error: class, interface, or enum expected
return;
^
Main.java:48: error: class, interface, or enum expected
}
^
Main.java:51: error: class, interface, or enum expected
update1(id * 2,l,mid,i,val);
^
Main.java:52: error: class, interface, or enum expected
update1(id * 2 + 1,mid + 1,r,i,val);
^
Main.java:54: error: class, interface, or enum expected
st[id].f = min(st[id * 2].f,st[id * 2 + 1].f);
^
Main.java:55: error: class, interface, or enum expected
}
^
Main.java:61: error: class, interface, or enum expected
}
^
Main.java:65: error: class, interface, or enum expected
return;
^
Main.java:66: error: class, interface, or enum expected
}
^
Main.java:69: error: class, interface, or enum expected
update2(id * 2,l,mid,i,val);
^
Main.java:70: error: class, interface, or enum expected
update2(id * 2 + 1,mid + 1,r,i,val);
^
Main.java:72: error: class, interface, or enum expected
st[id].se = min(st[id * 2].se,st[id * 2 + 1].se);
^
Main.java:73: error: class, interface, or enum expected
}
^
Main.java:79: error: class, interface, or enum expected
}
^
Main.java:83: error: class, interface, or enum expected
}
^
Main.java:87: error: class, interface, or enum expected
return min(get1(id * 2,l,mid,u,v),get1(id * 2 + 1,mid + 1,r,u,v));
^
Main.java:88: error: class, interface, or enum expected
}
^
Main.java:94: error: class, interface, or enum expected
}
^
Main.java:98: error: class, interface, or enum expected
}
^
Main.java:102: error: class, interface, or enum expected
return min(get2(id * 2,l,mid,u,v),get2(id * 2 + 1,mid + 1,r,u,v));
^
Main.java:103: error: class, interface, or enum expected
}
^
Main.java:111: error: class, interface, or enum expected
for(int i = 1; i <= n - 1; ++i){
^
Main.java:111: error: class, interface, or enum expected
for(int i = 1; i <= n - 1; ++i){
^
Main.java:111: error: class, interface, or enum expected
for(int i = 1; i <= n - 1; ++i){
^
Main.java:113: error: class, interface, or enum expected
cin >> u >> v;
^
Main.java:114: error: class, interface, or enum expected
}
^
Main.java:118: error: class, interface, or enum expected
while(q--){
^
Main.java:120: error: class, interface, or enum expected
cin >> type;
^
Main.java:122: error: class, interface, or enum expected
if(type == 1){
^
Main.java:124: error: class, interface, or enum expected
cin >> v >> c;
^
Main.java:125: error: class, interface, or enum expected
update1(1,1,n,v,c);
^
Main.java:126: error: class, interface, or enum expected
update2(1,1,n,v,c);
^
Main.java:127: error: class, interface, or enum expected
}
^
Main.java:130: error: class, interface, or enum expected
cin >> v;
^
Main.java:132: error: class, interface, or enum expected
ll res1 = v - 1;
^
Main.java:133: error: class, interface, or enum expected
ll res2 = min(v - 1,get1(1,1,n,v + 1,n) - v);
^
Main.java:134: error: class, interface, or enum expected
ll res3 = min(v - 1,get2(1,1,n,1,v) + v);
^
Main.java:136: error: class, interface, or enum expected
cout << min({res1,res2,res3}) << endl;
^
Main.java:137: error: class, interface, or enum expected
}
^
Main.java:141: error: class, interface, or enum expected
}
^
81 errors