problem_id stringlengths 6 6 | buggy_code stringlengths 8 526k ⌀ | fixed_code stringlengths 12 526k ⌀ | labels listlengths 0 15 ⌀ | buggy_submission_id int64 1 1.54M ⌀ | fixed_submission_id int64 2 1.54M ⌀ | user_id stringlengths 10 10 ⌀ | language stringclasses 9 values |
|---|---|---|---|---|---|---|---|
p02984 | #include <iostream>
#include <vector>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a(n);
int m = 0;
for (int i = 0; i < n; ++i) {
cin >> a[i];
m = a[i] * 2 - m;
}
m /= 2;
for (int i = 0; i < n; ++i) {
cout << m;
if (i < n - 1) {
cout << " ";
m = a[i] * 2 - m;
}
}
cout << endl;
}
| #include <iostream>
#include <vector>
using namespace std;
int main() {
int n;
cin >> n;
vector<long> a(n);
long m = 0;
for (int i = 0; i < n; ++i) {
cin >> a[i];
m = a[i] * 2 - m;
}
m /= 2;
for (int i = 0; i < n; ++i) {
cout << m;
if (i < n - 1) {
cout << " ";
m = a[i] * 2 - m;
}
}
cout << endl;
}
| [
"variable_declaration.type.primitive.change"
] | 792,585 | 792,586 | u532096498 | cpp |
p02984 | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
template <class T>
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
ll gcd(ll a, ll b) {
if (a % b == 0)
return (b);
else
return (gcd(b, a % b));
}
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
vector<int> bfs(vvi L, int S) { // List,Start
vector<int> v(L.size(), -1);
v[S] = 0;
queue<int> q;
q.push(S);
while (!q.empty()) {
int a = q.front();
q.pop();
for (int x : L[a]) {
if (v[x] == -1) {
v[x] = v[a] + 1;
q.push(x);
}
}
}
return v;
}
void initialize() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
// cout << fixed << setprecision(15);
}
/////////////////////////////////////////
int main() {
initialize();
int N;
cin >> N;
int A[N];
rep(i, N) {
cin >> A[i];
A[i] *= 2;
}
int B[N + 1];
B[0] = 0;
rep(i, N) { B[i + 1] = A[i] - B[i]; }
B[0] = B[N] / 2;
rep(i, N) { B[i + 1] = A[i] - B[i]; }
rep(j, N) cout << B[j] << (j == N - 1 ? "\n" : " ");
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
template <class T>
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
ll gcd(ll a, ll b) {
if (a % b == 0)
return (b);
else
return (gcd(b, a % b));
}
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
vector<int> bfs(vvi L, int S) { // List,Start
vector<int> v(L.size(), -1);
v[S] = 0;
queue<int> q;
q.push(S);
while (!q.empty()) {
int a = q.front();
q.pop();
for (int x : L[a]) {
if (v[x] == -1) {
v[x] = v[a] + 1;
q.push(x);
}
}
}
return v;
}
void initialize() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
// cout << fixed << setprecision(15);
}
/////////////////////////////////////////
int main() {
initialize();
int N;
cin >> N;
ll A[N];
rep(i, N) {
cin >> A[i];
A[i] *= 2;
}
ll B[N + 1];
B[0] = 0;
rep(i, N) { B[i + 1] = A[i] - B[i]; }
B[0] = B[N] / 2;
rep(i, N) { B[i + 1] = A[i] - B[i]; }
rep(j, N) cout << B[j] << (j == N - 1 ? "\n" : " ");
return 0;
}
| [
"variable_declaration.type.change"
] | 792,587 | 792,588 | u944316525 | cpp |
p02984 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<long> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
a[i] *= 2;
}
int nans = a[0];
for (int i = 0; i < (n - 1) / 2; i++) {
nans -= a[2 * (i + 1) - 1];
nans += a[2 * (i + 1)];
}
nans /= 2;
cout << nans;
vector<long> ans(n);
ans[0] = nans;
for (int i = 1; i < n; i++) {
ans[i] = a[i - 1] - ans[i - 1];
}
for (int i = 1; i < n; i++) {
cout << " " << ans[i];
}
cout << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<long> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
a[i] *= 2;
}
long nans = a[0];
for (int i = 0; i < (n - 1) / 2; i++) {
nans -= a[2 * (i + 1) - 1];
nans += a[2 * (i + 1)];
}
nans /= 2;
cout << nans;
vector<long> ans(n);
ans[0] = nans;
for (int i = 1; i < n; i++) {
ans[i] = a[i - 1] - ans[i - 1];
}
for (int i = 1; i < n; i++) {
cout << " " << ans[i];
}
cout << endl;
}
| [
"variable_declaration.type.primitive.change"
] | 792,597 | 792,598 | u637284188 | cpp |
p02984 | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>
using namespace std;
#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)
using Pi = pair<int, int>;
using ll = long long;
const int INF = 1 << 28;
string to_string(string s) { return s; }
template <class T> string to_string(vector<T> v) {
string ret = "{";
for (int i = 0; i < v.size() - 1; ++i) {
ret += to_string(v[i]) + ",";
}
if (v.size() > 0) {
ret += to_string(v.back());
}
ret += "}";
return ret;
}
void debug() { cerr << endl; }
template <class Head, class... Tail> void debug(Head head, Tail... tail) {
cerr << to_string(head) << " ";
debug(tail...);
}
void print() { cout << endl; }
template <class Head, class... Tail> void print(Head head, Tail... tail) {
cout << to_string(head);
print(tail...);
}
void get() {}
template <class Head, class... Tail> void get(Head &head, Tail &...tail) {
cin >> head;
get(tail...);
}
template <class T> void getv(vector<T> &vec) {
for (int i = 0; i < vec.size(); ++i)
cin >> vec[i];
}
int main() {
int N;
get(N);
vector<ll> A(N);
FOR(i, N) cin >> A[i];
int a = 0;
FOR(i, N) {
if (i % 2 == 0) {
a += A[i] * 2;
} else {
a -= A[i] * 2;
}
}
a /= 2;
cout << a << " ";
FORIN(i, 1, N) {
a = (A[i - 1] - a / 2) * 2;
if (i < N - 1) {
cout << a << " ";
} else {
cout << a << endl;
}
}
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>
using namespace std;
#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)
using Pi = pair<int, int>;
using ll = long long;
const int INF = 1 << 28;
string to_string(string s) { return s; }
template <class T> string to_string(vector<T> v) {
string ret = "{";
for (int i = 0; i < v.size() - 1; ++i) {
ret += to_string(v[i]) + ",";
}
if (v.size() > 0) {
ret += to_string(v.back());
}
ret += "}";
return ret;
}
void debug() { cerr << endl; }
template <class Head, class... Tail> void debug(Head head, Tail... tail) {
cerr << to_string(head) << " ";
debug(tail...);
}
void print() { cout << endl; }
template <class Head, class... Tail> void print(Head head, Tail... tail) {
cout << to_string(head);
print(tail...);
}
void get() {}
template <class Head, class... Tail> void get(Head &head, Tail &...tail) {
cin >> head;
get(tail...);
}
template <class T> void getv(vector<T> &vec) {
for (int i = 0; i < vec.size(); ++i)
cin >> vec[i];
}
int main() {
int N;
get(N);
vector<ll> A(N);
FOR(i, N) cin >> A[i];
ll a = 0;
FOR(i, N) {
if (i % 2 == 0) {
a += A[i] * 2;
} else {
a -= A[i] * 2;
}
}
a /= 2;
cout << a << " ";
FORIN(i, 1, N) {
a = (A[i - 1] - a / 2) * 2;
if (i < N - 1) {
cout << a << " ";
} else {
cout << a << endl;
}
}
return 0;
} | [
"variable_declaration.type.change"
] | 792,610 | 792,611 | u656771711 | cpp |
p02984 | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int main() {
int n;
cin >> n;
ll a[100010];
ll s = 0;
ll s1 = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
s += a[i];
if (i & 1)
s1 += a[i];
}
s /= 2;
ll x[100010];
x[0] = s - s1;
for (int i = 1; i < n; i++) {
x[i] = a[i - 1] - x[i - 1];
}
for (int i = 0; i < n; i++) {
cout << x[i];
if (i < n - 1)
cout << " ";
}
cout << endl;
return 0;
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int main() {
int n;
cin >> n;
ll a[100010];
ll s = 0;
ll s1 = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
s += a[i];
if (i & 1)
s1 += a[i];
}
s /= 2;
ll x[100010];
x[0] = s - s1;
for (int i = 1; i < n; i++) {
x[i] = a[i - 1] - x[i - 1];
}
for (int i = 0; i < n; i++) {
cout << 2 * x[i];
if (i < n - 1)
cout << " ";
}
cout << endl;
return 0;
} | [
"expression.operation.binary.add"
] | 792,839 | 792,840 | u930898631 | cpp |
p02986 | #include <algorithm>
#include <array>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctype.h>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <unordered_map>
#include <utility>
#include <vector>
#define _USE_MATH_DEFINES
#include <iostream>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, double> pld;
typedef pair<double, double> pdd;
typedef pair<double, ll> pdl;
typedef pair<int, char> pic;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef priority_queue<ll, vector<ll>, greater<ll>> llgreaterq;
typedef priority_queue<pll, vector<pll>, greater<pll>> pllgreaterq;
typedef priority_queue<pair<ll, pll>, vector<pair<ll, pll>>,
greater<pair<ll, pll>>>
plpllgreaterq;
typedef priority_queue<vi, vector<vi>, greater<vi>> vigreaterq;
typedef priority_queue<vl, vector<vl>, greater<vl>> vlgreaterq;
template <class o, class p, class q>
using tuple3q = priority_queue<tuple<o, p, q>, vector<tuple<o, p, q>>,
greater<tuple<o, p, q>>>;
template <class o, class p, class q, class r>
using tuple4q = priority_queue<tuple<o, p, q, r>, vector<tuple<o, p, q, r>>,
greater<tuple<o, p, q, r>>>;
template <class o, class p, class q, class r, class s>
using tuple5q =
priority_queue<tuple<o, p, q, r, s>, vector<tuple<o, p, q, r, s>>,
greater<tuple<o, p, q, r, s>>>;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
#define bit(x, v) ((ll)x << v)
#define rep(x, n) for (ll x = 0; x < n; x++)
#define rep2(x, f, v) for (ll x = f; x < v; x++)
#define repe(v, x) for (auto v : x)
// 許容する誤差ε
#define EPS (1e-10)
// 2つのスカラーが等しいかどうか
#define EQ(a, b) (std::abs(a - b) < EPS)
// 2つのベクトルが等しいかどうか
#define EQV(a, b) (EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()))
#define all(a) a.begin(), a.end()
#define all0(a) memset(a, 0, sizeof(a))
#define allm1(a) memset(a, -1, sizeof(a))
#define put_float(v) \
cout << fixed << setprecision(10); \
cout << v << endl
#define put(v) cout << v << endl
#define vinsert(v, p, x) v.insert(v.begin() + p, x)
#define vsort(v) sort(all(v));
#define vdesc(v) \
vsort(v); \
reverse(all(v))
#define dup(v) v.erase(unique(all(v)), v.end())
#define ion(i, j) ((i & (1LL << j)) > 0)
#define next(i) \
i++; \
i %= 2
#define Len size()
#define ull unsignd long long
#define psp(a, b) push_back(make_pair(a, b))
#define psp2(a, b) push(make_pair(a, b))
#define cini(a) \
a; \
cin >> a
#define infa(a, b) (a + b) % INF
#define infm(a, b) (a * b) % INF
#define infd(a, b) (a * modinv(b)) % INF
#define infs(a, b) (a + INF - b) % INF
#define inf(a) (a) %= INF
#define inff(a) ((a) % INF)
#define No cout << "No" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define YES cout << "YES" << endl
#define smal -INF *INF
#define big INF *INF
ll INF = 1000000007;
const int MAX = 2000010;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll getpow(ll b, ll x, ll md) {
ll t = b;
ll res = 1;
while (x > 0) {
if (x & 1) {
res *= t;
res %= md;
}
x >>= 1;
t *= t;
t %= md;
}
return res % md;
}
ll getpow(ll b, ll x) { return getpow(b, x, INF); }
ll modinv(ll x) { return getpow(x, INF - 2); }
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
class mint {
int md = 1000000007;
public:
long long x;
mint(ll x, ll md) {
this->md = md;
this->x = (x % md + md) % md;
}
mint(long long x = 0) : x((x % md + md) % md) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint &a) {
if ((x += a.x) >= md)
x -= md;
return *this;
}
mint &operator-=(const mint &a) {
if ((x += md - a.x) >= md)
x -= md;
return *this;
}
mint &operator*=(const mint &a) {
(x *= a.x) %= md;
return *this;
}
mint operator+(const mint &a) const {
mint res(*this);
return res += a;
}
mint operator-(const mint &a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint &a) const {
mint res(*this);
return res *= a;
}
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(md - 2); }
mint &operator/=(const mint &a) { return (*this) *= a.inv(); }
mint operator/(const mint &a) const {
mint res(*this);
return res /= a;
}
friend ostream &operator<<(ostream &os, const mint &m) {
os << m.x;
return os;
}
};
int pr[100010];
int lank[100010];
void uini(int n) {
for (size_t i = 0; i <= n; i++) {
pr[i] = i;
lank[i] = 1;
}
}
int parent(int x) {
if (x == pr[x])
return x;
return pr[x] = parent(pr[x]);
}
int same(int x, int y) { return parent(x) == parent(y); }
bool unit(int x, int y) {
int px = parent(x);
int py = parent(y);
if (px == py)
return false;
if (lank[py] < lank[px]) {
pr[py] = px;
lank[px] += lank[py];
} else {
pr[px] = py;
lank[py] += lank[px];
}
return true;
}
ll n, m;
int ci = 0;
struct Node {
int key;
int priority;
Node *parent, *left, *right;
Node(int key, int priority);
Node() {}
};
Node NIL;
Node::Node(int key, int priority) : key(key), priority(priority) {
left = &NIL;
right = &NIL;
}
Node *root = new Node();
void cenrec(Node *k) {
if (k->key == NIL.key)
return;
cenrec(k->left);
cout << " " << k->key;
cenrec(k->right);
}
void fastrec(Node *k) {
if (k->key == NIL.key)
return;
cout << " " << k->key;
fastrec(k->left);
fastrec(k->right);
}
void insert(Node *v) {
Node *y = &NIL;
Node *x = root;
while (x->key != NIL.key) {
y = x;
if (v->key < x->key) {
x = x->left;
} else {
x = x->right;
}
}
v->parent = y;
if (y->key == NIL.key) {
root = v;
} else if (v->key < y->key) {
y->left = v;
} else {
y->right = v;
}
}
Node *find(Node *k, ll v) {
if (k->key == NIL.key)
return &NIL;
if (k->key == v)
return k;
if (v < k->key)
return find(k->left, v);
return find(k->right, v);
}
void delp12(Node *x) {
if (x->key == NIL.key)
return;
Node *l = x->left;
Node *r = x->right;
Node *pr = x->parent;
if (l->key == NIL.key && r->key == NIL.key) {
if (pr->left == x) {
pr->left = &NIL;
} else
pr->right = &NIL;
} else if (l->key != NIL.key) {
if (pr->left == x) {
pr->left = l;
} else
pr->right = l;
l->parent = pr;
} else if (r->key != NIL.key) {
if (pr->left == x) {
pr->left = r;
} else
pr->right = r;
r->parent = pr;
}
}
Node *get_next(Node *k) {
if (k->key == NIL.key)
return &NIL;
Node *res = get_next(k->left);
if (res->key != NIL.key)
return res;
return k;
}
void del(Node *x) {
if (x->key == NIL.key)
return;
Node *l = x->left;
Node *r = x->right;
Node *pr = x->parent;
if (l->key != NIL.key && r->key != NIL.key) {
Node *nex = get_next(r);
x->key = nex->key;
delp12(nex);
} else {
delp12(x);
}
}
Node *rightRotate(Node *t) {
Node *s = t->left;
t->left = s->right;
s->right = t;
return s;
}
Node *leftRotate(Node *t) {
Node *s = t->right;
t->right = s->left;
s->left = t;
return s;
}
Node *_insert(Node *t, int key, int priority) {
if (t->key == NIL.key) {
return new Node(key, priority);
}
if (key == t->key) {
return t;
}
if (key < t->key) {
t->left = _insert(t->left, key, priority);
if (t->priority < t->left->priority) {
t = rightRotate(t);
}
} else {
t->right = _insert(t->right, key, priority);
if (t->priority < t->right->priority) {
t = leftRotate(t);
}
}
return t;
}
Node *delete1(Node *t, int key);
Node *_delete(Node *t, int key) {
if (t->left->key == NIL.key && t->right->key == NIL.key) {
return &NIL;
} else if (t->left->key == NIL.key) {
t = leftRotate(t);
} else if (t->right->key == NIL.key) {
t = rightRotate(t);
} else {
if (t->left->priority > t->right->priority) {
t = rightRotate(t);
} else
t = leftRotate(t);
}
return delete1(t, key);
}
Node *delete1(Node *t, int key) {
if (t->key == NIL.key) {
return &NIL;
}
if (key < t->key) {
t->left = delete1(t->left, key);
} else if (key > t->key) {
t->right = delete1(t->right, key);
} else
return _delete(t, key);
return t;
}
int H;
int left(int i) { return i * 2 + 1; }
int right(int i) { return i * 2 + 2; }
class edge {
public:
int from, to, i;
ll val;
edge() {}
edge(ll to) : to(to) {}
edge(ll to, ll i) : to(to), i(i) {}
edge(ll from, ll to, ll val) : from(from), to(to), val(val) {}
};
class LCA {
private:
vector<vector<edge>> v;
vector<vector<int>> parent;
vector<int> depth;
void dfs(int n, int m, int d) {
parent[0][n] = m;
depth[n] = d;
for (auto x : v[n]) {
if (x.to != m)
dfs(x.to, n, d + 1);
}
}
public:
LCA(ll N, ll root, vector<vector<edge>> &tree) {
v = tree;
parent = vector<vector<int>>(21, vector<int>(N + 1, 0));
depth = vector<int>(N + 1, 0);
dfs(root, -1, 0);
for (int j = 0; j + 1 < 20; j++) {
for (int i = 1; i <= N; i++) {
if (parent[j][i] < 0)
parent[j + 1][i] = -1;
else
parent[j + 1][i] = parent[j][parent[j][i]];
}
}
}
int lca(int n, int m) {
if (depth[n] > depth[m])
swap(n, m);
for (int j = 0; j < 20; j++) {
if ((depth[m] - depth[n]) >> j & 1)
m = parent[j][m];
}
if (n == m)
return n;
for (int j = 19; j >= 0; j--) {
if (parent[j][n] != parent[j][m]) {
n = parent[j][n];
m = parent[j][m];
}
}
return parent[0][n];
}
int dep(int n) { return depth[n]; }
};
ll k;
int _rank[1010];
int temp[1010];
bool compare_sa(int i, int j) {
if (_rank[i] != _rank[j])
return _rank[i] < _rank[j];
else {
int ri = i + k <= n ? _rank[i + k] : -1;
int rj = j + k <= n ? _rank[j + k] : -1;
return ri < rj;
}
}
void construct_sa(string S, int *sa) {
n = S.length();
for (size_t i = 0; i <= n; i++) {
sa[i] = i;
_rank[i] = i < n ? S[i] : -1;
}
for (k = 1; k <= n; k *= 2) {
sort(sa, sa + n + 1, compare_sa);
// saはソート後の接尾辞の並びになっている、rankは元の位置のindexを保持したまま、更新されている。
// ピンとこなかった部分
temp[sa[0]] = 0;
for (size_t i = 1; i <= n; i++) {
temp[sa[i]] = temp[sa[i - 1]] + (compare_sa(sa[i - 1], sa[i]) ? 1 : 0);
}
for (size_t i = 0; i <= n; i++) {
_rank[i] = temp[i];
}
}
}
bool contain(string S, int *sa, string T) {
int a = 0, b = S.length();
// sa は 接尾辞が辞書順に並んでいる、入っているのはその位置のインデックス
while (b - a > 1) {
int c = (a + b) / 2;
if (S.compare(sa[c], T.length(), T) < 0)
a = c;
else
b = c;
}
return S.compare(sa[b], T.length(), T) == 0;
}
#define bit(x, v) ((ll)x << v)
class BIT {
static const int MAX_N = 500010;
public:
BIT() { memset(bit, 0, sizeof(bit)); }
ll bit[MAX_N + 1], n;
ll sum(int i) {
ll s = 0;
while (i > 0) {
s += bit[i];
i -= i & -i;
}
return s;
}
void add(int i, int x) {
while (i <= n) {
bit[i] += x;
i += i & -i;
}
}
};
struct UnionFind {
vector<int> A;
UnionFind(int n) : A(n, -1) {}
int find(int x) {
if (A[x] < 0)
return x;
return A[x] = find(A[x]);
}
void unite(int x, int y) {
x = find(x), y = find(y);
if (x == y)
return;
if (A[x] > A[y])
swap(x, y);
A[x] += A[y];
A[y] = x;
}
int ngroups() {
int ans = 0;
for (auto a : A)
if (a < 0)
ans++;
return ans;
}
};
vector<ll> getp(ll n) {
vector<ll> res;
ll a = 2;
if (n % 2 == 0) {
res.push_back(2);
while (n % 2 == 0)
n /= 2;
}
for (ll i = 3; i * i <= n; i += 2) {
if (n % i == 0) {
res.push_back(i);
while (n % i == 0)
n /= i;
}
}
if (n != 1)
res.push_back(n);
return res;
}
vector<ll> getp2(ll n) {
vector<ll> res;
ll a = 2;
if (n % 2 == 0) {
while (n % 2 == 0) {
n /= 2;
res.push_back(2);
}
}
for (ll i = 3; i * i <= n; i += 2) {
if (n % i == 0) {
while (n % i == 0) {
n /= i;
res.push_back(i);
}
}
}
if (n != 1)
res.push_back(n);
return res;
}
vector<pll> getp3(ll n) {
vector<pll> res;
ll a = 2;
int si = 0;
if (n % 2 == 0) {
res.push_back(make_pair(2, 0));
while (n % 2 == 0) {
n /= 2;
res[si].second++;
}
si++;
}
for (ll i = 3; i * i <= n; i += 2) {
if (n % i == 0) {
res.push_back(make_pair(i, 0));
while (n % i == 0) {
n /= i;
res[si].second++;
}
si++;
}
}
if (n != 1) {
res.push_back(make_pair(n, 1));
}
return res;
}
vector<ll> getDivisors(ll n) {
vector<ll> res;
ll a = 2;
res.push_back(1);
for (ll i = 2; i * i <= n; i++) {
if (n % i == 0) {
res.push_back(i);
if (n / i != i)
res.push_back(n / i);
}
}
return res;
}
struct ve {
public:
vector<ve> child;
int _t = INF;
ve(int t) : _t(t) {}
ve(ve _left, ve _right) {
_t = _left._t + _right._t;
child.push_back(_left);
child.push_back(_right);
}
bool operator<(const ve &t) const { return _t > t._t; }
};
vector<bool> elas(ll n) {
vector<bool> r(n);
fill(r.begin(), r.end(), 1);
r[0] = 0;
r[1] = 0;
for (ll i = 2; i * i < n; i++) {
if (!r[i])
continue;
ll ti = i * 2;
while (ti < n) {
r[ti] = false;
ti += i;
}
}
return r;
}
bool isPrime(ll v) {
for (ll i = 2; i * i <= v; i++) {
if (v % i == 0)
return false;
}
return true;
}
class SegTree {
public:
const static int MAX_N = 100010;
const static int DAT_SIZE = (1 << 18) - 1;
int N, Q;
int A[MAX_N];
ll data[DAT_SIZE], datb[DAT_SIZE];
void init(int _n) {
N = 1;
while (N < _n)
N <<= 1;
memset(data, 0, sizeof(data));
memset(datb, 0, sizeof(datb));
}
void init(int _n, ll iv) {
N = 1;
while (N < _n)
N <<= 1;
rep(i, DAT_SIZE) {
data[i] = iv;
datb[i] = iv;
}
}
void add(int a, int b, int x) { add(a, b + 1, x, 0, 0, N); }
void add(int a, int b, int x, int k, int l, int r) {
if (a <= l && r <= b) {
data[k] += x;
} else if (l < b && a < r) {
datb[k] += (min(b, r) - max(a, l)) * x;
add(a, b, x, k * 2 + 1, l, (l + r) / 2);
add(a, b, x, k * 2 + 2, (l + r) / 2, r);
}
}
void change(int a, int b, int x) { change(a, b + 1, x, 0, 0, N); }
void change(int a, int b, int x, int k, int l, int r) {
if (a <= l && r <= b) {
data[k] = x;
} else if (l < b && a < r) {
datb[k] = x;
change(a, b, x, k * 2 + 1, l, (l + r) / 2);
change(a, b, x, k * 2 + 2, (l + r) / 2, r);
}
}
ll sum(int a, int b) { return sum(a, b + 1, 0, 0, N); }
ll sum(int a, int b, int k, int l, int r) {
if (b <= l || r <= a) {
return 0;
}
if (a <= l && r <= b) {
return data[k] * (r - l) + datb[k];
}
ll res = (min(b, r) - max(a, l)) * data[k];
res += sum(a, b, k * 2 + 1, l, (l + r) / 2);
res += sum(a, b, k * 2 + 2, (l + r) / 2, r);
return res;
}
};
class Segment;
class Circle;
class Point {
public:
double x, y;
Point(double x = 0, double y = 0) : x(x), y(y) {}
Point operator+(Point p) { return Point(x + p.x, y + p.y); }
Point operator-(Point p) { return Point(x - p.x, y - p.y); }
Point operator*(double a) { return Point(a * x, a * y); }
Point operator/(double a) { return Point(x / a, y / a); }
double abs() { return sqrt(norm()); }
double norm() { return x * x + y * y; }
bool operator<(const Point &p) const { return x != p.x ? x < p.x : y < p.y; }
bool operator==(const Point &p) const {
return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
}
static double dot(Point a, Point b) { return a.x * b.x + a.y * b.y; }
static double cross(Point a, Point b) { return a.x * b.y - a.y * b.x; }
static bool isOrthogonal(Point a, Point b) { return EQ(dot(a, b), 0.0); }
static bool isOrthogonal(Point a1, Point a2, Point b1, Point b2) {
return isOrthogonal(a1 - a2, b1 - b2);
}
static bool isOrthogonal(Segment s1, Segment s2);
static bool isPalallel(Point a, Point b) { return EQ(cross(a, b), 0.0); }
static bool isPalallel(Point a1, Point a2, Point b1, Point b2) {
return isPalallel(a1 - a2, b1 - b2);
}
static bool isPalallel(Segment s1, Segment s2);
static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;
static int ccw(Point p0, Point p1, Point p2) {
// 線分はp0とp1でp2がどこにあるかを探る
Point a = p1 - p0;
Point b = p2 - p0;
if (cross(a, b) > EPS)
return COUNTER_CLOCKWISE;
if (cross(a, b) < -EPS)
return CLOCKWISE;
if (dot(a, b) < -EPS)
return ONLINE_BACK;
if (a.norm() < b.norm())
return ONLINE_FRONT;
return ON_SEGMENT;
}
static bool intersect(Point p1, Point p2, Point p3, Point p4) {
return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 &&
ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0);
}
static bool intersect(Segment s1, Segment s2);
static Point project(Segment s, Point p);
static Point reflect(Segment s, Point p);
static Point getDistance(Point a, Point b) { return (a - b).abs(); }
static double getDistanceLP(Segment s, Point p);
static double getDistanceSP(Segment s, Point p);
static double getDistance(Segment s1, Segment s2);
static Point getIntersection(Segment s1, Segment s2);
static pair<Point, Point> crossPoints(Circle c, Segment s);
static int contains(vector<Point> g, Point p) {
int n = g.size();
bool x = false;
rep(i, n) {
Point a = g[i] - p, b = g[(i + 1) % n] - p;
// 線の上に載っているか
if (std::abs(cross(a, b)) < EPS && dot(a, b) < EPS)
return 1;
// pを基準として上下にあるか
// または外積が正か?(→にあるか)
if (a.y > b.y)
swap(a, b);
if (a.y < EPS && EPS < b.y && cross(a, b) > EPS)
x = !x;
}
return x ? 2 : 0;
}
static vector<Point> andrewScan(vector<Point> s) {
vector<Point> u, l;
if (s.size() < 3)
return s;
sort(all(s));
u.push_back(s[0]);
u.push_back(s[1]);
l.push_back(s[s.size() - 1]);
l.push_back(s[s.size() - 2]);
for (int i = 2; i < s.size(); i++) {
for (int _n = u.size();
_n >= 2 && ccw(u[_n - 2], u[_n - 1], s[i]) > CLOCKWISE; _n--) {
u.pop_back();
}
u.push_back(s[i]);
}
for (int i = s.size() - 3; i >= 0; i--) {
for (int _n = l.size();
_n >= 2 && ccw(l[_n - 2], l[_n - 1], s[i]) > CLOCKWISE; _n--) {
l.pop_back();
}
l.push_back(s[i]);
}
reverse(all(l));
for (int i = u.size() - 2; i >= 1; i--) {
l.push_back(u[i]);
}
return l;
}
void get_cin() { cin >> x >> y; }
};
class Segment {
public:
Point p1, p2;
Segment() {}
Segment(Point p1, Point p2) : p1(p1), p2(p2) {}
void get_cin() { cin >> p1.x >> p1.y >> p2.x >> p2.y; }
Point p1tp2() { return p2 - p1; }
Point p2tp1() { return p1 - p2; }
double abs() { return std::abs(norm()); }
double norm() { return (p2 - p1).norm(); }
};
bool Point::isOrthogonal(Segment s1, Segment s2) {
return EQ(dot(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}
bool Point::isPalallel(Segment s1, Segment s2) {
return EQ(cross(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}
bool Point::intersect(Segment s1, Segment s2) {
return intersect(s1.p1, s1.p2, s2.p1, s2.p2);
}
Point Point::project(Segment s, Point p) {
Point base = s.p2 - s.p1;
double r = Point::dot(p - s.p1, base) / base.norm();
return s.p1 + base * r;
}
Point Point::reflect(Segment s, Point p) { return (project(s, p) * 2) - p; }
double Point::getDistanceLP(Segment s, Point p) {
return std::abs(cross(s.p2 - s.p1, p - s.p1) / (s.p2 - s.p1).abs());
}
double Point::getDistanceSP(Segment s, Point p) {
if (dot(s.p2 - s.p1, p - s.p1) < 0.0)
return (p - s.p1).abs();
if (dot(s.p1 - s.p2, p - s.p2) < 0.0)
return (p - s.p2).abs();
return getDistanceLP(s, p);
}
double Point::getDistance(Segment s1, Segment s2) {
if (intersect(s1, s2))
return 0.0;
return min({getDistanceSP(s1, s2.p1), getDistanceSP(s1, s2.p2),
getDistanceSP(s2, s1.p1), getDistanceSP(s2, s1.p2)});
}
Point Point::getIntersection(Segment s1, Segment s2) {
// (s1.p1 - s2.p1).norm()
auto bs = s1.p2 - s1.p1;
auto n1 = s2.p1 - s1.p1;
auto n2 = s2.p2 - s1.p1;
auto c1 = std::abs(cross(n1, bs)) / bs.norm();
auto c2 = std::abs(cross(n2, bs)) / bs.norm();
return s2.p1 + (s2.p2 - s2.p1) * (c1 / (c1 + c2));
// c1:c2=t:1-t
// c2t=(1-t)c1
// t/(1-t)=c1/(c1+c2)
//
}
double arg(Point p) { return atan2(p.y, p.x); }
Point polar(double a, double r) { return Point(cos(r) * a, sin(r) * a); }
class Circle {
public:
Point c;
double r;
Circle(Point c = Point(), double r = 0.0) : c(c), r(r) {}
void get_cin() { cin >> c.x >> c.y >> r; }
static pair<Point, Point> getCrossPoints(Circle c1, Circle c2) {
double d = (c1.c - c2.c).abs(); // 中心点どうしの距離
double a = acos((c1.r * c1.r + d * d - c2.r * c2.r) / (2 * c1.r * d));
double t = arg(c2.c - c1.c);
return make_pair(c1.c + polar(c1.r, t + a), c1.c + polar(c1.r, t - a));
}
};
pair<Point, Point> Point::crossPoints(Circle c, Segment s) {
auto pp = project(s, c.c);
auto f = (pp - c.c).norm();
auto mu = sqrt(c.r * c.r - f);
auto e = s.p1tp2() / s.p1tp2().abs();
return make_pair(pp + e * mu, pp - e * mu);
}
ll divRm(string s, ll x) {
ll r = 0;
for (ll i = 0; i < s.size(); i++) {
r *= 10;
r += s[i] - '0';
r %= x;
}
return r;
}
ll cmbi(ll x, ll b) {
ll res = 1;
for (size_t i = 0; i < b; i++) {
res *= x - i;
res %= INF;
res *= inv[b - i];
res %= INF;
}
return res;
}
double digsum(ll x) {
ll res = 0;
while (x > 0) {
res += x % 10;
x /= 10;
}
return res;
}
bool check_parindrome(string s) {
int n = s.size();
rep(i, n / 2) {
if (s[i] != s[n - i - 1]) {
return false;
}
}
return true;
}
ll npr(ll n, ll r) {
if (r == 0)
return 1;
return inff(fac[n] * modinv(fac[n - r]));
}
vl zalgo(string s) {
ll c = 0;
vl a(s.size());
ll si = s.size();
rep2(i, 1, s.size()) {
if (i + a[i - c] < c + a[c]) {
a[i] = a[i - c];
} else {
ll j = max(0LL, a[c] - (i - c));
while (i + j < si && s[j] == s[i + j]) {
j++;
}
a[i] = j;
c = i;
}
}
a[0] = s.size();
return a;
}
string decStrNum(string s) {
ll si = s.size();
for (int i = si - 1; i >= 0; i--) {
if (s[i] == '0') {
s[i] = '9';
continue;
}
s[i] = s[i] - 1;
break;
}
return s;
}
// ここまでライブラリ
// ここからコード
struct query {
ll c, d, i;
bool lca;
};
vector<query> Q[100010];
ll ans[100010];
pll col[100010];
ll c[100010], d[100010];
vector<vector<edge>> es;
void euler(ll x, ll f, ll di) {
for (auto v : Q[x]) {
ll dis = di - col[v.c].second + col[v.c].first * v.d;
if (v.lca) {
ans[v.i] -= dis * 2;
} else {
ans[v.i] += dis;
}
}
for (auto v : es[x]) {
if (v.to == f)
continue;
ll co = c[v.i];
col[co].first++;
col[co].second += d[v.i];
euler(v.to, x, di + d[v.i]);
col[co].first--;
col[co].second -= d[v.i];
}
}
void solv() {
ll q;
cin >> n >> q;
es = vector<vector<edge>>(n + 1);
rep(i, n - 1) {
ll a, b;
cin >> a >> b >> c[i] >> d[i];
es[a].push_back({b, i});
es[b].push_back({a, i});
}
LCA lca(n, 1, es);
rep(i, q) {
ll x, y, u, v;
cin >> x >> y >> u >> v;
Q[u].push_back({x, y, i, false});
Q[v].push_back({x, y, i, false});
Q[lca.lca(u, v)].push_back({x, y, i, false});
}
euler(1, 0, 0);
rep(i, q) { cout << ans[i] << endl; }
}
int main() {
COMinit();
solv();
return 0;
}
| #include <algorithm>
#include <array>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctype.h>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <unordered_map>
#include <utility>
#include <vector>
#define _USE_MATH_DEFINES
#include <iostream>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, double> pld;
typedef pair<double, double> pdd;
typedef pair<double, ll> pdl;
typedef pair<int, char> pic;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef priority_queue<ll, vector<ll>, greater<ll>> llgreaterq;
typedef priority_queue<pll, vector<pll>, greater<pll>> pllgreaterq;
typedef priority_queue<pair<ll, pll>, vector<pair<ll, pll>>,
greater<pair<ll, pll>>>
plpllgreaterq;
typedef priority_queue<vi, vector<vi>, greater<vi>> vigreaterq;
typedef priority_queue<vl, vector<vl>, greater<vl>> vlgreaterq;
template <class o, class p, class q>
using tuple3q = priority_queue<tuple<o, p, q>, vector<tuple<o, p, q>>,
greater<tuple<o, p, q>>>;
template <class o, class p, class q, class r>
using tuple4q = priority_queue<tuple<o, p, q, r>, vector<tuple<o, p, q, r>>,
greater<tuple<o, p, q, r>>>;
template <class o, class p, class q, class r, class s>
using tuple5q =
priority_queue<tuple<o, p, q, r, s>, vector<tuple<o, p, q, r, s>>,
greater<tuple<o, p, q, r, s>>>;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
#define bit(x, v) ((ll)x << v)
#define rep(x, n) for (ll x = 0; x < n; x++)
#define rep2(x, f, v) for (ll x = f; x < v; x++)
#define repe(v, x) for (auto v : x)
// 許容する誤差ε
#define EPS (1e-10)
// 2つのスカラーが等しいかどうか
#define EQ(a, b) (std::abs(a - b) < EPS)
// 2つのベクトルが等しいかどうか
#define EQV(a, b) (EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()))
#define all(a) a.begin(), a.end()
#define all0(a) memset(a, 0, sizeof(a))
#define allm1(a) memset(a, -1, sizeof(a))
#define put_float(v) \
cout << fixed << setprecision(10); \
cout << v << endl
#define put(v) cout << v << endl
#define vinsert(v, p, x) v.insert(v.begin() + p, x)
#define vsort(v) sort(all(v));
#define vdesc(v) \
vsort(v); \
reverse(all(v))
#define dup(v) v.erase(unique(all(v)), v.end())
#define ion(i, j) ((i & (1LL << j)) > 0)
#define next(i) \
i++; \
i %= 2
#define Len size()
#define ull unsignd long long
#define psp(a, b) push_back(make_pair(a, b))
#define psp2(a, b) push(make_pair(a, b))
#define cini(a) \
a; \
cin >> a
#define infa(a, b) (a + b) % INF
#define infm(a, b) (a * b) % INF
#define infd(a, b) (a * modinv(b)) % INF
#define infs(a, b) (a + INF - b) % INF
#define inf(a) (a) %= INF
#define inff(a) ((a) % INF)
#define No cout << "No" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define YES cout << "YES" << endl
#define smal -INF *INF
#define big INF *INF
ll INF = 1000000007;
const int MAX = 2000010;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll getpow(ll b, ll x, ll md) {
ll t = b;
ll res = 1;
while (x > 0) {
if (x & 1) {
res *= t;
res %= md;
}
x >>= 1;
t *= t;
t %= md;
}
return res % md;
}
ll getpow(ll b, ll x) { return getpow(b, x, INF); }
ll modinv(ll x) { return getpow(x, INF - 2); }
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
class mint {
int md = 1000000007;
public:
long long x;
mint(ll x, ll md) {
this->md = md;
this->x = (x % md + md) % md;
}
mint(long long x = 0) : x((x % md + md) % md) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint &a) {
if ((x += a.x) >= md)
x -= md;
return *this;
}
mint &operator-=(const mint &a) {
if ((x += md - a.x) >= md)
x -= md;
return *this;
}
mint &operator*=(const mint &a) {
(x *= a.x) %= md;
return *this;
}
mint operator+(const mint &a) const {
mint res(*this);
return res += a;
}
mint operator-(const mint &a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint &a) const {
mint res(*this);
return res *= a;
}
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(md - 2); }
mint &operator/=(const mint &a) { return (*this) *= a.inv(); }
mint operator/(const mint &a) const {
mint res(*this);
return res /= a;
}
friend ostream &operator<<(ostream &os, const mint &m) {
os << m.x;
return os;
}
};
int pr[100010];
int lank[100010];
void uini(int n) {
for (size_t i = 0; i <= n; i++) {
pr[i] = i;
lank[i] = 1;
}
}
int parent(int x) {
if (x == pr[x])
return x;
return pr[x] = parent(pr[x]);
}
int same(int x, int y) { return parent(x) == parent(y); }
bool unit(int x, int y) {
int px = parent(x);
int py = parent(y);
if (px == py)
return false;
if (lank[py] < lank[px]) {
pr[py] = px;
lank[px] += lank[py];
} else {
pr[px] = py;
lank[py] += lank[px];
}
return true;
}
ll n, m;
int ci = 0;
struct Node {
int key;
int priority;
Node *parent, *left, *right;
Node(int key, int priority);
Node() {}
};
Node NIL;
Node::Node(int key, int priority) : key(key), priority(priority) {
left = &NIL;
right = &NIL;
}
Node *root = new Node();
void cenrec(Node *k) {
if (k->key == NIL.key)
return;
cenrec(k->left);
cout << " " << k->key;
cenrec(k->right);
}
void fastrec(Node *k) {
if (k->key == NIL.key)
return;
cout << " " << k->key;
fastrec(k->left);
fastrec(k->right);
}
void insert(Node *v) {
Node *y = &NIL;
Node *x = root;
while (x->key != NIL.key) {
y = x;
if (v->key < x->key) {
x = x->left;
} else {
x = x->right;
}
}
v->parent = y;
if (y->key == NIL.key) {
root = v;
} else if (v->key < y->key) {
y->left = v;
} else {
y->right = v;
}
}
Node *find(Node *k, ll v) {
if (k->key == NIL.key)
return &NIL;
if (k->key == v)
return k;
if (v < k->key)
return find(k->left, v);
return find(k->right, v);
}
void delp12(Node *x) {
if (x->key == NIL.key)
return;
Node *l = x->left;
Node *r = x->right;
Node *pr = x->parent;
if (l->key == NIL.key && r->key == NIL.key) {
if (pr->left == x) {
pr->left = &NIL;
} else
pr->right = &NIL;
} else if (l->key != NIL.key) {
if (pr->left == x) {
pr->left = l;
} else
pr->right = l;
l->parent = pr;
} else if (r->key != NIL.key) {
if (pr->left == x) {
pr->left = r;
} else
pr->right = r;
r->parent = pr;
}
}
Node *get_next(Node *k) {
if (k->key == NIL.key)
return &NIL;
Node *res = get_next(k->left);
if (res->key != NIL.key)
return res;
return k;
}
void del(Node *x) {
if (x->key == NIL.key)
return;
Node *l = x->left;
Node *r = x->right;
Node *pr = x->parent;
if (l->key != NIL.key && r->key != NIL.key) {
Node *nex = get_next(r);
x->key = nex->key;
delp12(nex);
} else {
delp12(x);
}
}
Node *rightRotate(Node *t) {
Node *s = t->left;
t->left = s->right;
s->right = t;
return s;
}
Node *leftRotate(Node *t) {
Node *s = t->right;
t->right = s->left;
s->left = t;
return s;
}
Node *_insert(Node *t, int key, int priority) {
if (t->key == NIL.key) {
return new Node(key, priority);
}
if (key == t->key) {
return t;
}
if (key < t->key) {
t->left = _insert(t->left, key, priority);
if (t->priority < t->left->priority) {
t = rightRotate(t);
}
} else {
t->right = _insert(t->right, key, priority);
if (t->priority < t->right->priority) {
t = leftRotate(t);
}
}
return t;
}
Node *delete1(Node *t, int key);
Node *_delete(Node *t, int key) {
if (t->left->key == NIL.key && t->right->key == NIL.key) {
return &NIL;
} else if (t->left->key == NIL.key) {
t = leftRotate(t);
} else if (t->right->key == NIL.key) {
t = rightRotate(t);
} else {
if (t->left->priority > t->right->priority) {
t = rightRotate(t);
} else
t = leftRotate(t);
}
return delete1(t, key);
}
Node *delete1(Node *t, int key) {
if (t->key == NIL.key) {
return &NIL;
}
if (key < t->key) {
t->left = delete1(t->left, key);
} else if (key > t->key) {
t->right = delete1(t->right, key);
} else
return _delete(t, key);
return t;
}
int H;
int left(int i) { return i * 2 + 1; }
int right(int i) { return i * 2 + 2; }
class edge {
public:
int from, to, i;
ll val;
edge() {}
edge(ll to) : to(to) {}
edge(ll to, ll i) : to(to), i(i) {}
edge(ll from, ll to, ll val) : from(from), to(to), val(val) {}
};
class LCA {
private:
vector<vector<edge>> v;
vector<vector<int>> parent;
vector<int> depth;
void dfs(int n, int m, int d) {
parent[0][n] = m;
depth[n] = d;
for (auto x : v[n]) {
if (x.to != m)
dfs(x.to, n, d + 1);
}
}
public:
LCA(ll N, ll root, vector<vector<edge>> &tree) {
v = tree;
parent = vector<vector<int>>(21, vector<int>(N + 1, 0));
depth = vector<int>(N + 1, 0);
dfs(root, -1, 0);
for (int j = 0; j + 1 < 20; j++) {
for (int i = 1; i <= N; i++) {
if (parent[j][i] < 0)
parent[j + 1][i] = -1;
else
parent[j + 1][i] = parent[j][parent[j][i]];
}
}
}
int lca(int n, int m) {
if (depth[n] > depth[m])
swap(n, m);
for (int j = 0; j < 20; j++) {
if ((depth[m] - depth[n]) >> j & 1)
m = parent[j][m];
}
if (n == m)
return n;
for (int j = 19; j >= 0; j--) {
if (parent[j][n] != parent[j][m]) {
n = parent[j][n];
m = parent[j][m];
}
}
return parent[0][n];
}
int dep(int n) { return depth[n]; }
};
ll k;
int _rank[1010];
int temp[1010];
bool compare_sa(int i, int j) {
if (_rank[i] != _rank[j])
return _rank[i] < _rank[j];
else {
int ri = i + k <= n ? _rank[i + k] : -1;
int rj = j + k <= n ? _rank[j + k] : -1;
return ri < rj;
}
}
void construct_sa(string S, int *sa) {
n = S.length();
for (size_t i = 0; i <= n; i++) {
sa[i] = i;
_rank[i] = i < n ? S[i] : -1;
}
for (k = 1; k <= n; k *= 2) {
sort(sa, sa + n + 1, compare_sa);
// saはソート後の接尾辞の並びになっている、rankは元の位置のindexを保持したまま、更新されている。
// ピンとこなかった部分
temp[sa[0]] = 0;
for (size_t i = 1; i <= n; i++) {
temp[sa[i]] = temp[sa[i - 1]] + (compare_sa(sa[i - 1], sa[i]) ? 1 : 0);
}
for (size_t i = 0; i <= n; i++) {
_rank[i] = temp[i];
}
}
}
bool contain(string S, int *sa, string T) {
int a = 0, b = S.length();
// sa は 接尾辞が辞書順に並んでいる、入っているのはその位置のインデックス
while (b - a > 1) {
int c = (a + b) / 2;
if (S.compare(sa[c], T.length(), T) < 0)
a = c;
else
b = c;
}
return S.compare(sa[b], T.length(), T) == 0;
}
#define bit(x, v) ((ll)x << v)
class BIT {
static const int MAX_N = 500010;
public:
BIT() { memset(bit, 0, sizeof(bit)); }
ll bit[MAX_N + 1], n;
ll sum(int i) {
ll s = 0;
while (i > 0) {
s += bit[i];
i -= i & -i;
}
return s;
}
void add(int i, int x) {
while (i <= n) {
bit[i] += x;
i += i & -i;
}
}
};
struct UnionFind {
vector<int> A;
UnionFind(int n) : A(n, -1) {}
int find(int x) {
if (A[x] < 0)
return x;
return A[x] = find(A[x]);
}
void unite(int x, int y) {
x = find(x), y = find(y);
if (x == y)
return;
if (A[x] > A[y])
swap(x, y);
A[x] += A[y];
A[y] = x;
}
int ngroups() {
int ans = 0;
for (auto a : A)
if (a < 0)
ans++;
return ans;
}
};
vector<ll> getp(ll n) {
vector<ll> res;
ll a = 2;
if (n % 2 == 0) {
res.push_back(2);
while (n % 2 == 0)
n /= 2;
}
for (ll i = 3; i * i <= n; i += 2) {
if (n % i == 0) {
res.push_back(i);
while (n % i == 0)
n /= i;
}
}
if (n != 1)
res.push_back(n);
return res;
}
vector<ll> getp2(ll n) {
vector<ll> res;
ll a = 2;
if (n % 2 == 0) {
while (n % 2 == 0) {
n /= 2;
res.push_back(2);
}
}
for (ll i = 3; i * i <= n; i += 2) {
if (n % i == 0) {
while (n % i == 0) {
n /= i;
res.push_back(i);
}
}
}
if (n != 1)
res.push_back(n);
return res;
}
vector<pll> getp3(ll n) {
vector<pll> res;
ll a = 2;
int si = 0;
if (n % 2 == 0) {
res.push_back(make_pair(2, 0));
while (n % 2 == 0) {
n /= 2;
res[si].second++;
}
si++;
}
for (ll i = 3; i * i <= n; i += 2) {
if (n % i == 0) {
res.push_back(make_pair(i, 0));
while (n % i == 0) {
n /= i;
res[si].second++;
}
si++;
}
}
if (n != 1) {
res.push_back(make_pair(n, 1));
}
return res;
}
vector<ll> getDivisors(ll n) {
vector<ll> res;
ll a = 2;
res.push_back(1);
for (ll i = 2; i * i <= n; i++) {
if (n % i == 0) {
res.push_back(i);
if (n / i != i)
res.push_back(n / i);
}
}
return res;
}
struct ve {
public:
vector<ve> child;
int _t = INF;
ve(int t) : _t(t) {}
ve(ve _left, ve _right) {
_t = _left._t + _right._t;
child.push_back(_left);
child.push_back(_right);
}
bool operator<(const ve &t) const { return _t > t._t; }
};
vector<bool> elas(ll n) {
vector<bool> r(n);
fill(r.begin(), r.end(), 1);
r[0] = 0;
r[1] = 0;
for (ll i = 2; i * i < n; i++) {
if (!r[i])
continue;
ll ti = i * 2;
while (ti < n) {
r[ti] = false;
ti += i;
}
}
return r;
}
bool isPrime(ll v) {
for (ll i = 2; i * i <= v; i++) {
if (v % i == 0)
return false;
}
return true;
}
class SegTree {
public:
const static int MAX_N = 100010;
const static int DAT_SIZE = (1 << 18) - 1;
int N, Q;
int A[MAX_N];
ll data[DAT_SIZE], datb[DAT_SIZE];
void init(int _n) {
N = 1;
while (N < _n)
N <<= 1;
memset(data, 0, sizeof(data));
memset(datb, 0, sizeof(datb));
}
void init(int _n, ll iv) {
N = 1;
while (N < _n)
N <<= 1;
rep(i, DAT_SIZE) {
data[i] = iv;
datb[i] = iv;
}
}
void add(int a, int b, int x) { add(a, b + 1, x, 0, 0, N); }
void add(int a, int b, int x, int k, int l, int r) {
if (a <= l && r <= b) {
data[k] += x;
} else if (l < b && a < r) {
datb[k] += (min(b, r) - max(a, l)) * x;
add(a, b, x, k * 2 + 1, l, (l + r) / 2);
add(a, b, x, k * 2 + 2, (l + r) / 2, r);
}
}
void change(int a, int b, int x) { change(a, b + 1, x, 0, 0, N); }
void change(int a, int b, int x, int k, int l, int r) {
if (a <= l && r <= b) {
data[k] = x;
} else if (l < b && a < r) {
datb[k] = x;
change(a, b, x, k * 2 + 1, l, (l + r) / 2);
change(a, b, x, k * 2 + 2, (l + r) / 2, r);
}
}
ll sum(int a, int b) { return sum(a, b + 1, 0, 0, N); }
ll sum(int a, int b, int k, int l, int r) {
if (b <= l || r <= a) {
return 0;
}
if (a <= l && r <= b) {
return data[k] * (r - l) + datb[k];
}
ll res = (min(b, r) - max(a, l)) * data[k];
res += sum(a, b, k * 2 + 1, l, (l + r) / 2);
res += sum(a, b, k * 2 + 2, (l + r) / 2, r);
return res;
}
};
class Segment;
class Circle;
class Point {
public:
double x, y;
Point(double x = 0, double y = 0) : x(x), y(y) {}
Point operator+(Point p) { return Point(x + p.x, y + p.y); }
Point operator-(Point p) { return Point(x - p.x, y - p.y); }
Point operator*(double a) { return Point(a * x, a * y); }
Point operator/(double a) { return Point(x / a, y / a); }
double abs() { return sqrt(norm()); }
double norm() { return x * x + y * y; }
bool operator<(const Point &p) const { return x != p.x ? x < p.x : y < p.y; }
bool operator==(const Point &p) const {
return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
}
static double dot(Point a, Point b) { return a.x * b.x + a.y * b.y; }
static double cross(Point a, Point b) { return a.x * b.y - a.y * b.x; }
static bool isOrthogonal(Point a, Point b) { return EQ(dot(a, b), 0.0); }
static bool isOrthogonal(Point a1, Point a2, Point b1, Point b2) {
return isOrthogonal(a1 - a2, b1 - b2);
}
static bool isOrthogonal(Segment s1, Segment s2);
static bool isPalallel(Point a, Point b) { return EQ(cross(a, b), 0.0); }
static bool isPalallel(Point a1, Point a2, Point b1, Point b2) {
return isPalallel(a1 - a2, b1 - b2);
}
static bool isPalallel(Segment s1, Segment s2);
static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;
static int ccw(Point p0, Point p1, Point p2) {
// 線分はp0とp1でp2がどこにあるかを探る
Point a = p1 - p0;
Point b = p2 - p0;
if (cross(a, b) > EPS)
return COUNTER_CLOCKWISE;
if (cross(a, b) < -EPS)
return CLOCKWISE;
if (dot(a, b) < -EPS)
return ONLINE_BACK;
if (a.norm() < b.norm())
return ONLINE_FRONT;
return ON_SEGMENT;
}
static bool intersect(Point p1, Point p2, Point p3, Point p4) {
return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 &&
ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0);
}
static bool intersect(Segment s1, Segment s2);
static Point project(Segment s, Point p);
static Point reflect(Segment s, Point p);
static Point getDistance(Point a, Point b) { return (a - b).abs(); }
static double getDistanceLP(Segment s, Point p);
static double getDistanceSP(Segment s, Point p);
static double getDistance(Segment s1, Segment s2);
static Point getIntersection(Segment s1, Segment s2);
static pair<Point, Point> crossPoints(Circle c, Segment s);
static int contains(vector<Point> g, Point p) {
int n = g.size();
bool x = false;
rep(i, n) {
Point a = g[i] - p, b = g[(i + 1) % n] - p;
// 線の上に載っているか
if (std::abs(cross(a, b)) < EPS && dot(a, b) < EPS)
return 1;
// pを基準として上下にあるか
// または外積が正か?(→にあるか)
if (a.y > b.y)
swap(a, b);
if (a.y < EPS && EPS < b.y && cross(a, b) > EPS)
x = !x;
}
return x ? 2 : 0;
}
static vector<Point> andrewScan(vector<Point> s) {
vector<Point> u, l;
if (s.size() < 3)
return s;
sort(all(s));
u.push_back(s[0]);
u.push_back(s[1]);
l.push_back(s[s.size() - 1]);
l.push_back(s[s.size() - 2]);
for (int i = 2; i < s.size(); i++) {
for (int _n = u.size();
_n >= 2 && ccw(u[_n - 2], u[_n - 1], s[i]) > CLOCKWISE; _n--) {
u.pop_back();
}
u.push_back(s[i]);
}
for (int i = s.size() - 3; i >= 0; i--) {
for (int _n = l.size();
_n >= 2 && ccw(l[_n - 2], l[_n - 1], s[i]) > CLOCKWISE; _n--) {
l.pop_back();
}
l.push_back(s[i]);
}
reverse(all(l));
for (int i = u.size() - 2; i >= 1; i--) {
l.push_back(u[i]);
}
return l;
}
void get_cin() { cin >> x >> y; }
};
class Segment {
public:
Point p1, p2;
Segment() {}
Segment(Point p1, Point p2) : p1(p1), p2(p2) {}
void get_cin() { cin >> p1.x >> p1.y >> p2.x >> p2.y; }
Point p1tp2() { return p2 - p1; }
Point p2tp1() { return p1 - p2; }
double abs() { return std::abs(norm()); }
double norm() { return (p2 - p1).norm(); }
};
bool Point::isOrthogonal(Segment s1, Segment s2) {
return EQ(dot(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}
bool Point::isPalallel(Segment s1, Segment s2) {
return EQ(cross(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}
bool Point::intersect(Segment s1, Segment s2) {
return intersect(s1.p1, s1.p2, s2.p1, s2.p2);
}
Point Point::project(Segment s, Point p) {
Point base = s.p2 - s.p1;
double r = Point::dot(p - s.p1, base) / base.norm();
return s.p1 + base * r;
}
Point Point::reflect(Segment s, Point p) { return (project(s, p) * 2) - p; }
double Point::getDistanceLP(Segment s, Point p) {
return std::abs(cross(s.p2 - s.p1, p - s.p1) / (s.p2 - s.p1).abs());
}
double Point::getDistanceSP(Segment s, Point p) {
if (dot(s.p2 - s.p1, p - s.p1) < 0.0)
return (p - s.p1).abs();
if (dot(s.p1 - s.p2, p - s.p2) < 0.0)
return (p - s.p2).abs();
return getDistanceLP(s, p);
}
double Point::getDistance(Segment s1, Segment s2) {
if (intersect(s1, s2))
return 0.0;
return min({getDistanceSP(s1, s2.p1), getDistanceSP(s1, s2.p2),
getDistanceSP(s2, s1.p1), getDistanceSP(s2, s1.p2)});
}
Point Point::getIntersection(Segment s1, Segment s2) {
// (s1.p1 - s2.p1).norm()
auto bs = s1.p2 - s1.p1;
auto n1 = s2.p1 - s1.p1;
auto n2 = s2.p2 - s1.p1;
auto c1 = std::abs(cross(n1, bs)) / bs.norm();
auto c2 = std::abs(cross(n2, bs)) / bs.norm();
return s2.p1 + (s2.p2 - s2.p1) * (c1 / (c1 + c2));
// c1:c2=t:1-t
// c2t=(1-t)c1
// t/(1-t)=c1/(c1+c2)
//
}
double arg(Point p) { return atan2(p.y, p.x); }
Point polar(double a, double r) { return Point(cos(r) * a, sin(r) * a); }
class Circle {
public:
Point c;
double r;
Circle(Point c = Point(), double r = 0.0) : c(c), r(r) {}
void get_cin() { cin >> c.x >> c.y >> r; }
static pair<Point, Point> getCrossPoints(Circle c1, Circle c2) {
double d = (c1.c - c2.c).abs(); // 中心点どうしの距離
double a = acos((c1.r * c1.r + d * d - c2.r * c2.r) / (2 * c1.r * d));
double t = arg(c2.c - c1.c);
return make_pair(c1.c + polar(c1.r, t + a), c1.c + polar(c1.r, t - a));
}
};
pair<Point, Point> Point::crossPoints(Circle c, Segment s) {
auto pp = project(s, c.c);
auto f = (pp - c.c).norm();
auto mu = sqrt(c.r * c.r - f);
auto e = s.p1tp2() / s.p1tp2().abs();
return make_pair(pp + e * mu, pp - e * mu);
}
ll divRm(string s, ll x) {
ll r = 0;
for (ll i = 0; i < s.size(); i++) {
r *= 10;
r += s[i] - '0';
r %= x;
}
return r;
}
ll cmbi(ll x, ll b) {
ll res = 1;
for (size_t i = 0; i < b; i++) {
res *= x - i;
res %= INF;
res *= inv[b - i];
res %= INF;
}
return res;
}
double digsum(ll x) {
ll res = 0;
while (x > 0) {
res += x % 10;
x /= 10;
}
return res;
}
bool check_parindrome(string s) {
int n = s.size();
rep(i, n / 2) {
if (s[i] != s[n - i - 1]) {
return false;
}
}
return true;
}
ll npr(ll n, ll r) {
if (r == 0)
return 1;
return inff(fac[n] * modinv(fac[n - r]));
}
vl zalgo(string s) {
ll c = 0;
vl a(s.size());
ll si = s.size();
rep2(i, 1, s.size()) {
if (i + a[i - c] < c + a[c]) {
a[i] = a[i - c];
} else {
ll j = max(0LL, a[c] - (i - c));
while (i + j < si && s[j] == s[i + j]) {
j++;
}
a[i] = j;
c = i;
}
}
a[0] = s.size();
return a;
}
string decStrNum(string s) {
ll si = s.size();
for (int i = si - 1; i >= 0; i--) {
if (s[i] == '0') {
s[i] = '9';
continue;
}
s[i] = s[i] - 1;
break;
}
return s;
}
// ここまでライブラリ
// ここからコード
struct query {
ll c, d, i;
bool lca;
};
vector<query> Q[100010];
ll ans[100010];
pll col[100010];
ll c[100010], d[100010];
vector<vector<edge>> es;
void euler(ll x, ll f, ll di) {
for (auto v : Q[x]) {
ll dis = di - col[v.c].second + col[v.c].first * v.d;
if (v.lca) {
ans[v.i] -= dis * 2;
} else {
ans[v.i] += dis;
}
}
for (auto v : es[x]) {
if (v.to == f)
continue;
ll co = c[v.i];
col[co].first++;
col[co].second += d[v.i];
euler(v.to, x, di + d[v.i]);
col[co].first--;
col[co].second -= d[v.i];
}
}
void solv() {
ll q;
cin >> n >> q;
es = vector<vector<edge>>(n + 1);
rep(i, n - 1) {
ll a, b;
cin >> a >> b >> c[i] >> d[i];
es[a].push_back({b, i});
es[b].push_back({a, i});
}
LCA lca(n, 1, es);
rep(i, q) {
ll x, y, u, v;
cin >> x >> y >> u >> v;
Q[u].push_back({x, y, i, false});
Q[v].push_back({x, y, i, false});
Q[lca.lca(u, v)].push_back({x, y, i, true});
}
euler(1, 0, 0);
rep(i, q) { cout << ans[i] << endl; }
}
int main() {
COMinit();
solv();
return 0;
}
| [
"misc.opposites",
"call.arguments.change"
] | 793,187 | 793,188 | u224756887 | cpp |
p02986 | #include <algorithm>
#include <array>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctype.h>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <unordered_map>
#include <utility>
#include <vector>
#define _USE_MATH_DEFINES
#include <iostream>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, double> pld;
typedef pair<double, double> pdd;
typedef pair<double, ll> pdl;
typedef pair<int, char> pic;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef priority_queue<ll, vector<ll>, greater<ll>> llgreaterq;
typedef priority_queue<pll, vector<pll>, greater<pll>> pllgreaterq;
typedef priority_queue<pair<ll, pll>, vector<pair<ll, pll>>,
greater<pair<ll, pll>>>
plpllgreaterq;
typedef priority_queue<vi, vector<vi>, greater<vi>> vigreaterq;
typedef priority_queue<vl, vector<vl>, greater<vl>> vlgreaterq;
template <class o, class p, class q>
using tuple3q = priority_queue<tuple<o, p, q>, vector<tuple<o, p, q>>,
greater<tuple<o, p, q>>>;
template <class o, class p, class q, class r>
using tuple4q = priority_queue<tuple<o, p, q, r>, vector<tuple<o, p, q, r>>,
greater<tuple<o, p, q, r>>>;
template <class o, class p, class q, class r, class s>
using tuple5q =
priority_queue<tuple<o, p, q, r, s>, vector<tuple<o, p, q, r, s>>,
greater<tuple<o, p, q, r, s>>>;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
#define bit(x, v) ((ll)x << v)
#define rep(x, n) for (ll x = 0; x < n; x++)
#define rep2(x, f, v) for (ll x = f; x < v; x++)
#define repe(v, x) for (auto v : x)
// 許容する誤差ε
#define EPS (1e-10)
// 2つのスカラーが等しいかどうか
#define EQ(a, b) (std::abs(a - b) < EPS)
// 2つのベクトルが等しいかどうか
#define EQV(a, b) (EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()))
#define all(a) a.begin(), a.end()
#define all0(a) memset(a, 0, sizeof(a))
#define allm1(a) memset(a, -1, sizeof(a))
#define put_float(v) \
cout << fixed << setprecision(10); \
cout << v << endl
#define put(v) cout << v << endl
#define vinsert(v, p, x) v.insert(v.begin() + p, x)
#define vsort(v) sort(all(v));
#define dup(v) v.erase(unique(all(v)), v.end())
#define ion(i, j) ((i & (1LL << j)) > 0)
#define next(i) \
i++; \
i %= 2
#define Len size()
#define ull unsignd long long
#define psp(a, b) push_back(make_pair(a, b))
#define psp2(a, b) push(make_pair(a, b))
#define cini(a) \
a; \
cin >> a
#define infa(a, b) (a + b) % INF
#define infm(a, b) (a * b) % INF
#define infd(a, b) (a * modinv(b)) % INF
#define infs(a, b) (a + INF - b) % INF
#define inf(a) (a) %= INF
#define inff(a) ((a) % INF)
#define No cout << "No" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define YES cout << "YES" << endl
#define smal -INF *INF
#define big INF *INF
const ll INF = 1000000007;
const int MAX = 2000010;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll getpow(ll b, ll x, ll md) {
ll t = b;
ll res = 1;
while (x > 0) {
if (x & 1) {
res *= t;
res %= md;
}
x >>= 1;
t *= t;
t %= md;
}
return res;
}
ll getpow(ll b, ll x) { return getpow(b, x, INF); }
ll modinv(ll x) { return getpow(x, INF - 2); }
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
class mint {
int md = 1000000007;
public:
long long x;
mint(ll x, ll md) {
this->md = md;
this->x = (x % md + md) % md;
}
mint(long long x = 0) : x((x % md + md) % md) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint &a) {
if ((x += a.x) >= md)
x -= md;
return *this;
}
mint &operator-=(const mint &a) {
if ((x += md - a.x) >= md)
x -= md;
return *this;
}
mint &operator*=(const mint &a) {
(x *= a.x) %= md;
return *this;
}
mint operator+(const mint &a) const {
mint res(*this);
return res += a;
}
mint operator-(const mint &a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint &a) const {
mint res(*this);
return res *= a;
}
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(md - 2); }
mint &operator/=(const mint &a) { return (*this) *= a.inv(); }
mint operator/(const mint &a) const {
mint res(*this);
return res /= a;
}
friend ostream &operator<<(ostream &os, const mint &m) {
os << m.x;
return os;
}
};
int pr[100010];
int lank[100010];
void uini(int n) {
for (size_t i = 0; i <= n; i++) {
pr[i] = i;
lank[i] = 1;
}
}
int parent(int x) {
if (x == pr[x])
return x;
return pr[x] = parent(pr[x]);
}
int same(int x, int y) { return parent(x) == parent(y); }
bool unit(int x, int y) {
int px = parent(x);
int py = parent(y);
if (px == py)
return false;
if (lank[py] < lank[px]) {
pr[py] = px;
lank[px] += lank[py];
} else {
pr[px] = py;
lank[py] += lank[px];
}
return true;
}
ll n;
int ci = 0;
struct Node {
int key;
int priority;
Node *parent, *left, *right;
Node(int key, int priority);
Node() {}
};
Node NIL;
Node::Node(int key, int priority) : key(key), priority(priority) {
left = &NIL;
right = &NIL;
}
Node *root = new Node();
void cenrec(Node *k) {
if (k->key == NIL.key)
return;
cenrec(k->left);
cout << " " << k->key;
cenrec(k->right);
}
void fastrec(Node *k) {
if (k->key == NIL.key)
return;
cout << " " << k->key;
fastrec(k->left);
fastrec(k->right);
}
void insert(Node *v) {
Node *y = &NIL;
Node *x = root;
while (x->key != NIL.key) {
y = x;
if (v->key < x->key) {
x = x->left;
} else {
x = x->right;
}
}
v->parent = y;
if (y->key == NIL.key) {
root = v;
} else if (v->key < y->key) {
y->left = v;
} else {
y->right = v;
}
}
Node *find(Node *k, ll v) {
if (k->key == NIL.key)
return &NIL;
if (k->key == v)
return k;
if (v < k->key)
return find(k->left, v);
return find(k->right, v);
}
void delp12(Node *x) {
if (x->key == NIL.key)
return;
Node *l = x->left;
Node *r = x->right;
Node *pr = x->parent;
if (l->key == NIL.key && r->key == NIL.key) {
if (pr->left == x) {
pr->left = &NIL;
} else
pr->right = &NIL;
} else if (l->key != NIL.key) {
if (pr->left == x) {
pr->left = l;
} else
pr->right = l;
l->parent = pr;
} else if (r->key != NIL.key) {
if (pr->left == x) {
pr->left = r;
} else
pr->right = r;
r->parent = pr;
}
}
Node *get_next(Node *k) {
if (k->key == NIL.key)
return &NIL;
Node *res = get_next(k->left);
if (res->key != NIL.key)
return res;
return k;
}
void del(Node *x) {
if (x->key == NIL.key)
return;
Node *l = x->left;
Node *r = x->right;
Node *pr = x->parent;
if (l->key != NIL.key && r->key != NIL.key) {
Node *nex = get_next(r);
x->key = nex->key;
delp12(nex);
} else {
delp12(x);
}
}
Node *rightRotate(Node *t) {
Node *s = t->left;
t->left = s->right;
s->right = t;
return s;
}
Node *leftRotate(Node *t) {
Node *s = t->right;
t->right = s->left;
s->left = t;
return s;
}
Node *_insert(Node *t, int key, int priority) {
if (t->key == NIL.key) {
return new Node(key, priority);
}
if (key == t->key) {
return t;
}
if (key < t->key) {
t->left = _insert(t->left, key, priority);
if (t->priority < t->left->priority) {
t = rightRotate(t);
}
} else {
t->right = _insert(t->right, key, priority);
if (t->priority < t->right->priority) {
t = leftRotate(t);
}
}
return t;
}
Node *delete1(Node *t, int key);
Node *_delete(Node *t, int key) {
if (t->left->key == NIL.key && t->right->key == NIL.key) {
return &NIL;
} else if (t->left->key == NIL.key) {
t = leftRotate(t);
} else if (t->right->key == NIL.key) {
t = rightRotate(t);
} else {
if (t->left->priority > t->right->priority) {
t = rightRotate(t);
} else
t = leftRotate(t);
}
return delete1(t, key);
}
Node *delete1(Node *t, int key) {
if (t->key == NIL.key) {
return &NIL;
}
if (key < t->key) {
t->left = delete1(t->left, key);
} else if (key > t->key) {
t->right = delete1(t->right, key);
} else
return _delete(t, key);
return t;
}
int H;
int left(int i) { return i * 2 + 1; }
int right(int i) { return i * 2 + 2; }
class edge {
public:
int from, to, i;
ll val;
edge() {}
edge(ll to) : to(to) {}
edge(ll to, ll i) : to(to), i(i) {}
edge(ll from, ll to, ll val) : from(from), to(to), val(val) {}
};
class LCA {
private:
vector<vector<edge>> v;
vector<vector<int>> parent;
vector<int> depth;
void dfs(int n, int m, int d) {
parent[0][n] = m;
depth[n] = d;
for (auto x : v[n]) {
if (x.to != m)
dfs(x.to, n, d + 1);
}
}
public:
LCA(ll N, ll root, vector<vector<edge>> &tree) {
v = tree;
parent = vector<vector<int>>(21, vector<int>(N + 1, 0));
depth = vector<int>(N + 1, 0);
dfs(root, -1, 0);
for (int j = 0; j + 1 < 20; j++) {
for (int i = 1; i <= N; i++) {
if (parent[j][i] < 0)
parent[j + 1][i] = -1;
else
parent[j + 1][i] = parent[j][parent[j][i]];
}
}
}
int lca(int n, int m) {
if (depth[n] > depth[m])
swap(n, m);
for (int j = 0; j < 20; j++) {
if ((depth[m] - depth[n]) >> j & 1)
m = parent[j][m];
}
if (n == m)
return n;
for (int j = 19; j >= 0; j--) {
if (parent[j][n] != parent[j][m]) {
n = parent[j][n];
m = parent[j][m];
}
}
return parent[0][n];
}
int dep(int n) { return depth[n]; }
};
ll k;
int _rank[1010];
int temp[1010];
bool compare_sa(int i, int j) {
if (_rank[i] != _rank[j])
return _rank[i] < _rank[j];
else {
int ri = i + k <= n ? _rank[i + k] : -1;
int rj = j + k <= n ? _rank[j + k] : -1;
return ri < rj;
}
}
void construct_sa(string S, int *sa) {
n = S.length();
for (size_t i = 0; i <= n; i++) {
sa[i] = i;
_rank[i] = i < n ? S[i] : -1;
}
for (k = 1; k <= n; k *= 2) {
sort(sa, sa + n + 1, compare_sa);
// saはソート後の接尾辞の並びになっている、rankは元の位置のindexを保持したまま、更新されている。
// ピンとこなかった部分
temp[sa[0]] = 0;
for (size_t i = 1; i <= n; i++) {
temp[sa[i]] = temp[sa[i - 1]] + (compare_sa(sa[i - 1], sa[i]) ? 1 : 0);
}
for (size_t i = 0; i <= n; i++) {
_rank[i] = temp[i];
}
}
}
bool contain(string S, int *sa, string T) {
int a = 0, b = S.length();
// sa は 接尾辞が辞書順に並んでいる、入っているのはその位置のインデックス
while (b - a > 1) {
int c = (a + b) / 2;
if (S.compare(sa[c], T.length(), T) < 0)
a = c;
else
b = c;
}
return S.compare(sa[b], T.length(), T) == 0;
}
#define bit(x, v) ((ll)x << v)
class BIT {
static const int MAX_N = 500010;
public:
BIT() { memset(bit, 0, sizeof(bit)); }
ll bit[MAX_N + 1], n;
ll sum(int i) {
ll s = 0;
while (i > 0) {
s += bit[i];
i -= i & -i;
}
return s;
}
void add(int i, int x) {
while (i <= n) {
bit[i] += x;
i += i & -i;
}
}
};
struct UnionFind {
vector<int> A;
UnionFind(int n) : A(n, -1) {}
int find(int x) {
if (A[x] < 0)
return x;
return A[x] = find(A[x]);
}
void unite(int x, int y) {
x = find(x), y = find(y);
if (x == y)
return;
if (A[x] > A[y])
swap(x, y);
A[x] += A[y];
A[y] = x;
}
int ngroups() {
int ans = 0;
for (auto a : A)
if (a < 0)
ans++;
return ans;
}
};
vector<ll> getp(ll n) {
vector<ll> res;
ll a = 2;
if (n % 2 == 0) {
res.push_back(2);
while (n % 2 == 0)
n /= 2;
}
for (ll i = 3; i * i <= n; i += 2) {
if (n % i == 0) {
res.push_back(i);
while (n % i == 0)
n /= i;
}
}
if (n != 1)
res.push_back(n);
return res;
}
vector<ll> getp2(ll n) {
vector<ll> res;
ll a = 2;
if (n % 2 == 0) {
while (n % 2 == 0) {
n /= 2;
res.push_back(2);
}
}
for (ll i = 3; i * i <= n; i += 2) {
if (n % i == 0) {
while (n % i == 0) {
n /= i;
res.push_back(i);
}
}
}
if (n != 1)
res.push_back(n);
return res;
}
vector<pll> getp3(ll n) {
vector<pll> res;
ll a = 2;
int si = 0;
if (n % 2 == 0) {
res.push_back(make_pair(2, 0));
while (n % 2 == 0) {
n /= 2;
res[si].second++;
}
si++;
}
for (ll i = 3; i * i <= n; i += 2) {
if (n % i == 0) {
res.push_back(make_pair(i, 0));
while (n % i == 0) {
n /= i;
res[si].second++;
}
si++;
}
}
if (n != 1) {
res.push_back(make_pair(n, 1));
}
return res;
}
vector<ll> getDivisors(ll n) {
vector<ll> res;
ll a = 2;
res.push_back(1);
for (ll i = 2; i * i <= n; i++) {
if (n % i == 0) {
res.push_back(i);
if (n / i != i)
res.push_back(n / i);
}
}
return res;
}
struct ve {
public:
vector<ve> child;
int _t = INF;
ve(int t) : _t(t) {}
ve(ve _left, ve _right) {
_t = _left._t + _right._t;
child.push_back(_left);
child.push_back(_right);
}
bool operator<(const ve &t) const { return _t > t._t; }
};
vector<bool> elas(ll n) {
vector<bool> r(n);
fill(r.begin(), r.end(), 1);
r[0] = 0;
r[1] = 0;
for (ll i = 2; i * i < n; i++) {
if (!r[i])
continue;
ll ti = i * 2;
while (ti < n) {
r[ti] = false;
ti += i;
}
}
return r;
}
bool isPrime(ll v) {
for (ll i = 2; i * i <= v; i++) {
if (v % i == 0)
return false;
}
return true;
}
class SegTree {
public:
const static int MAX_N = 100010;
const static int DAT_SIZE = (1 << 18) - 1;
int N, Q;
int A[MAX_N];
ll data[DAT_SIZE], datb[DAT_SIZE];
void init(int _n) {
N = 1;
while (N < _n)
N <<= 1;
memset(data, 0, sizeof(data));
memset(datb, 0, sizeof(datb));
}
void init(int _n, ll iv) {
N = 1;
while (N < _n)
N <<= 1;
rep(i, DAT_SIZE) {
data[i] = iv;
datb[i] = iv;
}
}
void add(int a, int b, int x) { add(a, b + 1, x, 0, 0, N); }
void add(int a, int b, int x, int k, int l, int r) {
if (a <= l && r <= b) {
data[k] += x;
} else if (l < b && a < r) {
datb[k] += (min(b, r) - max(a, l)) * x;
add(a, b, x, k * 2 + 1, l, (l + r) / 2);
add(a, b, x, k * 2 + 2, (l + r) / 2, r);
}
}
void change(int a, int b, int x) { change(a, b + 1, x, 0, 0, N); }
void change(int a, int b, int x, int k, int l, int r) {
if (a <= l && r <= b) {
data[k] = x;
} else if (l < b && a < r) {
datb[k] = x;
change(a, b, x, k * 2 + 1, l, (l + r) / 2);
change(a, b, x, k * 2 + 2, (l + r) / 2, r);
}
}
ll sum(int a, int b) { return sum(a, b + 1, 0, 0, N); }
ll sum(int a, int b, int k, int l, int r) {
if (b <= l || r <= a) {
return 0;
}
if (a <= l && r <= b) {
return data[k] * (r - l) + datb[k];
}
ll res = (min(b, r) - max(a, l)) * data[k];
res += sum(a, b, k * 2 + 1, l, (l + r) / 2);
res += sum(a, b, k * 2 + 2, (l + r) / 2, r);
return res;
}
};
class Segment;
class Circle;
class Point {
public:
double x, y;
Point(double x = 0, double y = 0) : x(x), y(y) {}
Point operator+(Point p) { return Point(x + p.x, y + p.y); }
Point operator-(Point p) { return Point(x - p.x, y - p.y); }
Point operator*(double a) { return Point(a * x, a * y); }
Point operator/(double a) { return Point(x / a, y / a); }
double abs() { return sqrt(norm()); }
double norm() { return x * x + y * y; }
bool operator<(const Point &p) const { return x != p.x ? x < p.x : y < p.y; }
bool operator==(const Point &p) const {
return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
}
static double dot(Point a, Point b) { return a.x * b.x + a.y * b.y; }
static double cross(Point a, Point b) { return a.x * b.y - a.y * b.x; }
static bool isOrthogonal(Point a, Point b) { return EQ(dot(a, b), 0.0); }
static bool isOrthogonal(Point a1, Point a2, Point b1, Point b2) {
return isOrthogonal(a1 - a2, b1 - b2);
}
static bool isOrthogonal(Segment s1, Segment s2);
static bool isPalallel(Point a, Point b) { return EQ(cross(a, b), 0.0); }
static bool isPalallel(Point a1, Point a2, Point b1, Point b2) {
return isPalallel(a1 - a2, b1 - b2);
}
static bool isPalallel(Segment s1, Segment s2);
static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;
static int ccw(Point p0, Point p1, Point p2) {
// 線分はp0とp1でp2がどこにあるかを探る
Point a = p1 - p0;
Point b = p2 - p0;
if (cross(a, b) > EPS)
return COUNTER_CLOCKWISE;
if (cross(a, b) < -EPS)
return CLOCKWISE;
if (dot(a, b) < -EPS)
return ONLINE_BACK;
if (a.norm() < b.norm())
return ONLINE_FRONT;
return ON_SEGMENT;
}
static bool intersect(Point p1, Point p2, Point p3, Point p4) {
return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 &&
ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0);
}
static bool intersect(Segment s1, Segment s2);
static Point project(Segment s, Point p);
static Point reflect(Segment s, Point p);
static Point getDistance(Point a, Point b) { return (a - b).abs(); }
static double getDistanceLP(Segment s, Point p);
static double getDistanceSP(Segment s, Point p);
static double getDistance(Segment s1, Segment s2);
static Point getIntersection(Segment s1, Segment s2);
static pair<Point, Point> crossPoints(Circle c, Segment s);
static int contains(vector<Point> g, Point p) {
int n = g.size();
bool x = false;
rep(i, n) {
Point a = g[i] - p, b = g[(i + 1) % n] - p;
// 線の上に載っているか
if (std::abs(cross(a, b)) < EPS && dot(a, b) < EPS)
return 1;
// pを基準として上下にあるか
// または外積が正か?(→にあるか)
if (a.y > b.y)
swap(a, b);
if (a.y < EPS && EPS < b.y && cross(a, b) > EPS)
x = !x;
}
return x ? 2 : 0;
}
static vector<Point> andrewScan(vector<Point> s) {
vector<Point> u, l;
if (s.size() < 3)
return s;
sort(all(s));
u.push_back(s[0]);
u.push_back(s[1]);
l.push_back(s[s.size() - 1]);
l.push_back(s[s.size() - 2]);
for (int i = 2; i < s.size(); i++) {
for (int _n = u.size();
_n >= 2 && ccw(u[_n - 2], u[_n - 1], s[i]) > CLOCKWISE; _n--) {
u.pop_back();
}
u.push_back(s[i]);
}
for (int i = s.size() - 3; i >= 0; i--) {
for (int _n = l.size();
_n >= 2 && ccw(l[_n - 2], l[_n - 1], s[i]) > CLOCKWISE; _n--) {
l.pop_back();
}
l.push_back(s[i]);
}
reverse(all(l));
for (int i = u.size() - 2; i >= 1; i--) {
l.push_back(u[i]);
}
return l;
}
void get_cin() { cin >> x >> y; }
};
class Segment {
public:
Point p1, p2;
Segment() {}
Segment(Point p1, Point p2) : p1(p1), p2(p2) {}
void get_cin() { cin >> p1.x >> p1.y >> p2.x >> p2.y; }
Point p1tp2() { return p2 - p1; }
Point p2tp1() { return p1 - p2; }
double abs() { return std::abs(norm()); }
double norm() { return (p2 - p1).norm(); }
};
bool Point::isOrthogonal(Segment s1, Segment s2) {
return EQ(dot(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}
bool Point::isPalallel(Segment s1, Segment s2) {
return EQ(cross(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}
bool Point::intersect(Segment s1, Segment s2) {
return intersect(s1.p1, s1.p2, s2.p1, s2.p2);
}
Point Point::project(Segment s, Point p) {
Point base = s.p2 - s.p1;
double r = Point::dot(p - s.p1, base) / base.norm();
return s.p1 + base * r;
}
Point Point::reflect(Segment s, Point p) { return (project(s, p) * 2) - p; }
double Point::getDistanceLP(Segment s, Point p) {
return std::abs(cross(s.p2 - s.p1, p - s.p1) / (s.p2 - s.p1).abs());
}
double Point::getDistanceSP(Segment s, Point p) {
if (dot(s.p2 - s.p1, p - s.p1) < 0.0)
return (p - s.p1).abs();
if (dot(s.p1 - s.p2, p - s.p2) < 0.0)
return (p - s.p2).abs();
return getDistanceLP(s, p);
}
double Point::getDistance(Segment s1, Segment s2) {
if (intersect(s1, s2))
return 0.0;
return min({getDistanceSP(s1, s2.p1), getDistanceSP(s1, s2.p2),
getDistanceSP(s2, s1.p1), getDistanceSP(s2, s1.p2)});
}
Point Point::getIntersection(Segment s1, Segment s2) {
// (s1.p1 - s2.p1).norm()
auto bs = s1.p2 - s1.p1;
auto n1 = s2.p1 - s1.p1;
auto n2 = s2.p2 - s1.p1;
auto c1 = std::abs(cross(n1, bs)) / bs.norm();
auto c2 = std::abs(cross(n2, bs)) / bs.norm();
return s2.p1 + (s2.p2 - s2.p1) * (c1 / (c1 + c2));
// c1:c2=t:1-t
// c2t=(1-t)c1
// t/(1-t)=c1/(c1+c2)
//
}
double arg(Point p) { return atan2(p.y, p.x); }
Point polar(double a, double r) { return Point(cos(r) * a, sin(r) * a); }
class Circle {
public:
Point c;
double r;
Circle(Point c = Point(), double r = 0.0) : c(c), r(r) {}
void get_cin() { cin >> c.x >> c.y >> r; }
static pair<Point, Point> getCrossPoints(Circle c1, Circle c2) {
double d = (c1.c - c2.c).abs(); // 中心点どうしの距離
double a = acos((c1.r * c1.r + d * d - c2.r * c2.r) / (2 * c1.r * d));
double t = arg(c2.c - c1.c);
return make_pair(c1.c + polar(c1.r, t + a), c1.c + polar(c1.r, t - a));
}
};
pair<Point, Point> Point::crossPoints(Circle c, Segment s) {
auto pp = project(s, c.c);
auto f = (pp - c.c).norm();
auto mu = sqrt(c.r * c.r - f);
auto e = s.p1tp2() / s.p1tp2().abs();
return make_pair(pp + e * mu, pp - e * mu);
}
ll divRm(string s, ll x) {
ll r = 0;
for (ll i = 0; i < s.size(); i++) {
r *= 10;
r += s[i] - '0';
r %= x;
}
return r;
}
ll cmbi(ll x, ll b) {
ll res = 1;
for (size_t i = 0; i < b; i++) {
res *= x - i;
res %= INF;
res *= inv[b - i];
res %= INF;
}
return res;
}
double digsum(ll x) {
ll res = 0;
while (x > 0) {
res += x % 10;
x /= 10;
}
return res;
}
bool check_parindrome(string s) {
int n = s.size();
rep(i, n / 2) {
if (s[i] != s[n - i - 1]) {
return false;
}
}
return true;
}
// ここまでライブラリ
// ここからコード
struct query {
ll col, d, i;
bool lca;
};
struct color {
ll c, d;
};
vector<vector<edge>> es;
ll c[100010], d[100010];
vector<query> Q[100010];
color co[100010];
ll ans[100010];
void eul(ll x, ll f, ll dis) {
for (auto v : Q[x]) {
ll val = dis - co[v.col].d + co[v.col].c * v.d;
if (v.lca) {
ans[v.i] -= val;
} else {
ans[v.i] += val;
}
}
for (auto v : es[x]) {
if (v.to == f)
continue;
ll col = c[v.i];
ll di = d[v.i];
co[col].c++;
co[col].d += di;
eul(v.to, x, dis + di);
co[col].c--;
co[col].d -= di;
}
}
void solv() {
ll q;
cin >> n >> q;
es = vector<vector<edge>>(n + 1);
rep(i, n - 1) {
ll a, b;
cin >> a >> b >> c[i] >> d[i];
es[a].push_back({b, i});
es[b].push_back({a, i});
}
LCA lca(n, 1, es);
rep(i, q) {
ll x, y, u, v;
cin >> x >> y >> u >> v;
Q[u].push_back({x, y, i, false});
Q[v].push_back({x, y, i, false});
Q[lca.lca(u, v)].push_back({x, y, i, true});
}
eul(1, 0, 0);
rep(i, q) { cout << ans[i] << endl; }
}
int main() {
COMinit();
solv();
return 0;
}
| #include <algorithm>
#include <array>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctype.h>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <unordered_map>
#include <utility>
#include <vector>
#define _USE_MATH_DEFINES
#include <iostream>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, double> pld;
typedef pair<double, double> pdd;
typedef pair<double, ll> pdl;
typedef pair<int, char> pic;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef priority_queue<ll, vector<ll>, greater<ll>> llgreaterq;
typedef priority_queue<pll, vector<pll>, greater<pll>> pllgreaterq;
typedef priority_queue<pair<ll, pll>, vector<pair<ll, pll>>,
greater<pair<ll, pll>>>
plpllgreaterq;
typedef priority_queue<vi, vector<vi>, greater<vi>> vigreaterq;
typedef priority_queue<vl, vector<vl>, greater<vl>> vlgreaterq;
template <class o, class p, class q>
using tuple3q = priority_queue<tuple<o, p, q>, vector<tuple<o, p, q>>,
greater<tuple<o, p, q>>>;
template <class o, class p, class q, class r>
using tuple4q = priority_queue<tuple<o, p, q, r>, vector<tuple<o, p, q, r>>,
greater<tuple<o, p, q, r>>>;
template <class o, class p, class q, class r, class s>
using tuple5q =
priority_queue<tuple<o, p, q, r, s>, vector<tuple<o, p, q, r, s>>,
greater<tuple<o, p, q, r, s>>>;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
#define bit(x, v) ((ll)x << v)
#define rep(x, n) for (ll x = 0; x < n; x++)
#define rep2(x, f, v) for (ll x = f; x < v; x++)
#define repe(v, x) for (auto v : x)
// 許容する誤差ε
#define EPS (1e-10)
// 2つのスカラーが等しいかどうか
#define EQ(a, b) (std::abs(a - b) < EPS)
// 2つのベクトルが等しいかどうか
#define EQV(a, b) (EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()))
#define all(a) a.begin(), a.end()
#define all0(a) memset(a, 0, sizeof(a))
#define allm1(a) memset(a, -1, sizeof(a))
#define put_float(v) \
cout << fixed << setprecision(10); \
cout << v << endl
#define put(v) cout << v << endl
#define vinsert(v, p, x) v.insert(v.begin() + p, x)
#define vsort(v) sort(all(v));
#define dup(v) v.erase(unique(all(v)), v.end())
#define ion(i, j) ((i & (1LL << j)) > 0)
#define next(i) \
i++; \
i %= 2
#define Len size()
#define ull unsignd long long
#define psp(a, b) push_back(make_pair(a, b))
#define psp2(a, b) push(make_pair(a, b))
#define cini(a) \
a; \
cin >> a
#define infa(a, b) (a + b) % INF
#define infm(a, b) (a * b) % INF
#define infd(a, b) (a * modinv(b)) % INF
#define infs(a, b) (a + INF - b) % INF
#define inf(a) (a) %= INF
#define inff(a) ((a) % INF)
#define No cout << "No" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define YES cout << "YES" << endl
#define smal -INF *INF
#define big INF *INF
const ll INF = 1000000007;
const int MAX = 2000010;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll getpow(ll b, ll x, ll md) {
ll t = b;
ll res = 1;
while (x > 0) {
if (x & 1) {
res *= t;
res %= md;
}
x >>= 1;
t *= t;
t %= md;
}
return res;
}
ll getpow(ll b, ll x) { return getpow(b, x, INF); }
ll modinv(ll x) { return getpow(x, INF - 2); }
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
class mint {
int md = 1000000007;
public:
long long x;
mint(ll x, ll md) {
this->md = md;
this->x = (x % md + md) % md;
}
mint(long long x = 0) : x((x % md + md) % md) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint &a) {
if ((x += a.x) >= md)
x -= md;
return *this;
}
mint &operator-=(const mint &a) {
if ((x += md - a.x) >= md)
x -= md;
return *this;
}
mint &operator*=(const mint &a) {
(x *= a.x) %= md;
return *this;
}
mint operator+(const mint &a) const {
mint res(*this);
return res += a;
}
mint operator-(const mint &a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint &a) const {
mint res(*this);
return res *= a;
}
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(md - 2); }
mint &operator/=(const mint &a) { return (*this) *= a.inv(); }
mint operator/(const mint &a) const {
mint res(*this);
return res /= a;
}
friend ostream &operator<<(ostream &os, const mint &m) {
os << m.x;
return os;
}
};
int pr[100010];
int lank[100010];
void uini(int n) {
for (size_t i = 0; i <= n; i++) {
pr[i] = i;
lank[i] = 1;
}
}
int parent(int x) {
if (x == pr[x])
return x;
return pr[x] = parent(pr[x]);
}
int same(int x, int y) { return parent(x) == parent(y); }
bool unit(int x, int y) {
int px = parent(x);
int py = parent(y);
if (px == py)
return false;
if (lank[py] < lank[px]) {
pr[py] = px;
lank[px] += lank[py];
} else {
pr[px] = py;
lank[py] += lank[px];
}
return true;
}
ll n;
int ci = 0;
struct Node {
int key;
int priority;
Node *parent, *left, *right;
Node(int key, int priority);
Node() {}
};
Node NIL;
Node::Node(int key, int priority) : key(key), priority(priority) {
left = &NIL;
right = &NIL;
}
Node *root = new Node();
void cenrec(Node *k) {
if (k->key == NIL.key)
return;
cenrec(k->left);
cout << " " << k->key;
cenrec(k->right);
}
void fastrec(Node *k) {
if (k->key == NIL.key)
return;
cout << " " << k->key;
fastrec(k->left);
fastrec(k->right);
}
void insert(Node *v) {
Node *y = &NIL;
Node *x = root;
while (x->key != NIL.key) {
y = x;
if (v->key < x->key) {
x = x->left;
} else {
x = x->right;
}
}
v->parent = y;
if (y->key == NIL.key) {
root = v;
} else if (v->key < y->key) {
y->left = v;
} else {
y->right = v;
}
}
Node *find(Node *k, ll v) {
if (k->key == NIL.key)
return &NIL;
if (k->key == v)
return k;
if (v < k->key)
return find(k->left, v);
return find(k->right, v);
}
void delp12(Node *x) {
if (x->key == NIL.key)
return;
Node *l = x->left;
Node *r = x->right;
Node *pr = x->parent;
if (l->key == NIL.key && r->key == NIL.key) {
if (pr->left == x) {
pr->left = &NIL;
} else
pr->right = &NIL;
} else if (l->key != NIL.key) {
if (pr->left == x) {
pr->left = l;
} else
pr->right = l;
l->parent = pr;
} else if (r->key != NIL.key) {
if (pr->left == x) {
pr->left = r;
} else
pr->right = r;
r->parent = pr;
}
}
Node *get_next(Node *k) {
if (k->key == NIL.key)
return &NIL;
Node *res = get_next(k->left);
if (res->key != NIL.key)
return res;
return k;
}
void del(Node *x) {
if (x->key == NIL.key)
return;
Node *l = x->left;
Node *r = x->right;
Node *pr = x->parent;
if (l->key != NIL.key && r->key != NIL.key) {
Node *nex = get_next(r);
x->key = nex->key;
delp12(nex);
} else {
delp12(x);
}
}
Node *rightRotate(Node *t) {
Node *s = t->left;
t->left = s->right;
s->right = t;
return s;
}
Node *leftRotate(Node *t) {
Node *s = t->right;
t->right = s->left;
s->left = t;
return s;
}
Node *_insert(Node *t, int key, int priority) {
if (t->key == NIL.key) {
return new Node(key, priority);
}
if (key == t->key) {
return t;
}
if (key < t->key) {
t->left = _insert(t->left, key, priority);
if (t->priority < t->left->priority) {
t = rightRotate(t);
}
} else {
t->right = _insert(t->right, key, priority);
if (t->priority < t->right->priority) {
t = leftRotate(t);
}
}
return t;
}
Node *delete1(Node *t, int key);
Node *_delete(Node *t, int key) {
if (t->left->key == NIL.key && t->right->key == NIL.key) {
return &NIL;
} else if (t->left->key == NIL.key) {
t = leftRotate(t);
} else if (t->right->key == NIL.key) {
t = rightRotate(t);
} else {
if (t->left->priority > t->right->priority) {
t = rightRotate(t);
} else
t = leftRotate(t);
}
return delete1(t, key);
}
Node *delete1(Node *t, int key) {
if (t->key == NIL.key) {
return &NIL;
}
if (key < t->key) {
t->left = delete1(t->left, key);
} else if (key > t->key) {
t->right = delete1(t->right, key);
} else
return _delete(t, key);
return t;
}
int H;
int left(int i) { return i * 2 + 1; }
int right(int i) { return i * 2 + 2; }
class edge {
public:
int from, to, i;
ll val;
edge() {}
edge(ll to) : to(to) {}
edge(ll to, ll i) : to(to), i(i) {}
edge(ll from, ll to, ll val) : from(from), to(to), val(val) {}
};
class LCA {
private:
vector<vector<edge>> v;
vector<vector<int>> parent;
vector<int> depth;
void dfs(int n, int m, int d) {
parent[0][n] = m;
depth[n] = d;
for (auto x : v[n]) {
if (x.to != m)
dfs(x.to, n, d + 1);
}
}
public:
LCA(ll N, ll root, vector<vector<edge>> &tree) {
v = tree;
parent = vector<vector<int>>(21, vector<int>(N + 1, 0));
depth = vector<int>(N + 1, 0);
dfs(root, -1, 0);
for (int j = 0; j + 1 < 20; j++) {
for (int i = 1; i <= N; i++) {
if (parent[j][i] < 0)
parent[j + 1][i] = -1;
else
parent[j + 1][i] = parent[j][parent[j][i]];
}
}
}
int lca(int n, int m) {
if (depth[n] > depth[m])
swap(n, m);
for (int j = 0; j < 20; j++) {
if ((depth[m] - depth[n]) >> j & 1)
m = parent[j][m];
}
if (n == m)
return n;
for (int j = 19; j >= 0; j--) {
if (parent[j][n] != parent[j][m]) {
n = parent[j][n];
m = parent[j][m];
}
}
return parent[0][n];
}
int dep(int n) { return depth[n]; }
};
ll k;
int _rank[1010];
int temp[1010];
bool compare_sa(int i, int j) {
if (_rank[i] != _rank[j])
return _rank[i] < _rank[j];
else {
int ri = i + k <= n ? _rank[i + k] : -1;
int rj = j + k <= n ? _rank[j + k] : -1;
return ri < rj;
}
}
void construct_sa(string S, int *sa) {
n = S.length();
for (size_t i = 0; i <= n; i++) {
sa[i] = i;
_rank[i] = i < n ? S[i] : -1;
}
for (k = 1; k <= n; k *= 2) {
sort(sa, sa + n + 1, compare_sa);
// saはソート後の接尾辞の並びになっている、rankは元の位置のindexを保持したまま、更新されている。
// ピンとこなかった部分
temp[sa[0]] = 0;
for (size_t i = 1; i <= n; i++) {
temp[sa[i]] = temp[sa[i - 1]] + (compare_sa(sa[i - 1], sa[i]) ? 1 : 0);
}
for (size_t i = 0; i <= n; i++) {
_rank[i] = temp[i];
}
}
}
bool contain(string S, int *sa, string T) {
int a = 0, b = S.length();
// sa は 接尾辞が辞書順に並んでいる、入っているのはその位置のインデックス
while (b - a > 1) {
int c = (a + b) / 2;
if (S.compare(sa[c], T.length(), T) < 0)
a = c;
else
b = c;
}
return S.compare(sa[b], T.length(), T) == 0;
}
#define bit(x, v) ((ll)x << v)
class BIT {
static const int MAX_N = 500010;
public:
BIT() { memset(bit, 0, sizeof(bit)); }
ll bit[MAX_N + 1], n;
ll sum(int i) {
ll s = 0;
while (i > 0) {
s += bit[i];
i -= i & -i;
}
return s;
}
void add(int i, int x) {
while (i <= n) {
bit[i] += x;
i += i & -i;
}
}
};
struct UnionFind {
vector<int> A;
UnionFind(int n) : A(n, -1) {}
int find(int x) {
if (A[x] < 0)
return x;
return A[x] = find(A[x]);
}
void unite(int x, int y) {
x = find(x), y = find(y);
if (x == y)
return;
if (A[x] > A[y])
swap(x, y);
A[x] += A[y];
A[y] = x;
}
int ngroups() {
int ans = 0;
for (auto a : A)
if (a < 0)
ans++;
return ans;
}
};
vector<ll> getp(ll n) {
vector<ll> res;
ll a = 2;
if (n % 2 == 0) {
res.push_back(2);
while (n % 2 == 0)
n /= 2;
}
for (ll i = 3; i * i <= n; i += 2) {
if (n % i == 0) {
res.push_back(i);
while (n % i == 0)
n /= i;
}
}
if (n != 1)
res.push_back(n);
return res;
}
vector<ll> getp2(ll n) {
vector<ll> res;
ll a = 2;
if (n % 2 == 0) {
while (n % 2 == 0) {
n /= 2;
res.push_back(2);
}
}
for (ll i = 3; i * i <= n; i += 2) {
if (n % i == 0) {
while (n % i == 0) {
n /= i;
res.push_back(i);
}
}
}
if (n != 1)
res.push_back(n);
return res;
}
vector<pll> getp3(ll n) {
vector<pll> res;
ll a = 2;
int si = 0;
if (n % 2 == 0) {
res.push_back(make_pair(2, 0));
while (n % 2 == 0) {
n /= 2;
res[si].second++;
}
si++;
}
for (ll i = 3; i * i <= n; i += 2) {
if (n % i == 0) {
res.push_back(make_pair(i, 0));
while (n % i == 0) {
n /= i;
res[si].second++;
}
si++;
}
}
if (n != 1) {
res.push_back(make_pair(n, 1));
}
return res;
}
vector<ll> getDivisors(ll n) {
vector<ll> res;
ll a = 2;
res.push_back(1);
for (ll i = 2; i * i <= n; i++) {
if (n % i == 0) {
res.push_back(i);
if (n / i != i)
res.push_back(n / i);
}
}
return res;
}
struct ve {
public:
vector<ve> child;
int _t = INF;
ve(int t) : _t(t) {}
ve(ve _left, ve _right) {
_t = _left._t + _right._t;
child.push_back(_left);
child.push_back(_right);
}
bool operator<(const ve &t) const { return _t > t._t; }
};
vector<bool> elas(ll n) {
vector<bool> r(n);
fill(r.begin(), r.end(), 1);
r[0] = 0;
r[1] = 0;
for (ll i = 2; i * i < n; i++) {
if (!r[i])
continue;
ll ti = i * 2;
while (ti < n) {
r[ti] = false;
ti += i;
}
}
return r;
}
bool isPrime(ll v) {
for (ll i = 2; i * i <= v; i++) {
if (v % i == 0)
return false;
}
return true;
}
class SegTree {
public:
const static int MAX_N = 100010;
const static int DAT_SIZE = (1 << 18) - 1;
int N, Q;
int A[MAX_N];
ll data[DAT_SIZE], datb[DAT_SIZE];
void init(int _n) {
N = 1;
while (N < _n)
N <<= 1;
memset(data, 0, sizeof(data));
memset(datb, 0, sizeof(datb));
}
void init(int _n, ll iv) {
N = 1;
while (N < _n)
N <<= 1;
rep(i, DAT_SIZE) {
data[i] = iv;
datb[i] = iv;
}
}
void add(int a, int b, int x) { add(a, b + 1, x, 0, 0, N); }
void add(int a, int b, int x, int k, int l, int r) {
if (a <= l && r <= b) {
data[k] += x;
} else if (l < b && a < r) {
datb[k] += (min(b, r) - max(a, l)) * x;
add(a, b, x, k * 2 + 1, l, (l + r) / 2);
add(a, b, x, k * 2 + 2, (l + r) / 2, r);
}
}
void change(int a, int b, int x) { change(a, b + 1, x, 0, 0, N); }
void change(int a, int b, int x, int k, int l, int r) {
if (a <= l && r <= b) {
data[k] = x;
} else if (l < b && a < r) {
datb[k] = x;
change(a, b, x, k * 2 + 1, l, (l + r) / 2);
change(a, b, x, k * 2 + 2, (l + r) / 2, r);
}
}
ll sum(int a, int b) { return sum(a, b + 1, 0, 0, N); }
ll sum(int a, int b, int k, int l, int r) {
if (b <= l || r <= a) {
return 0;
}
if (a <= l && r <= b) {
return data[k] * (r - l) + datb[k];
}
ll res = (min(b, r) - max(a, l)) * data[k];
res += sum(a, b, k * 2 + 1, l, (l + r) / 2);
res += sum(a, b, k * 2 + 2, (l + r) / 2, r);
return res;
}
};
class Segment;
class Circle;
class Point {
public:
double x, y;
Point(double x = 0, double y = 0) : x(x), y(y) {}
Point operator+(Point p) { return Point(x + p.x, y + p.y); }
Point operator-(Point p) { return Point(x - p.x, y - p.y); }
Point operator*(double a) { return Point(a * x, a * y); }
Point operator/(double a) { return Point(x / a, y / a); }
double abs() { return sqrt(norm()); }
double norm() { return x * x + y * y; }
bool operator<(const Point &p) const { return x != p.x ? x < p.x : y < p.y; }
bool operator==(const Point &p) const {
return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
}
static double dot(Point a, Point b) { return a.x * b.x + a.y * b.y; }
static double cross(Point a, Point b) { return a.x * b.y - a.y * b.x; }
static bool isOrthogonal(Point a, Point b) { return EQ(dot(a, b), 0.0); }
static bool isOrthogonal(Point a1, Point a2, Point b1, Point b2) {
return isOrthogonal(a1 - a2, b1 - b2);
}
static bool isOrthogonal(Segment s1, Segment s2);
static bool isPalallel(Point a, Point b) { return EQ(cross(a, b), 0.0); }
static bool isPalallel(Point a1, Point a2, Point b1, Point b2) {
return isPalallel(a1 - a2, b1 - b2);
}
static bool isPalallel(Segment s1, Segment s2);
static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;
static int ccw(Point p0, Point p1, Point p2) {
// 線分はp0とp1でp2がどこにあるかを探る
Point a = p1 - p0;
Point b = p2 - p0;
if (cross(a, b) > EPS)
return COUNTER_CLOCKWISE;
if (cross(a, b) < -EPS)
return CLOCKWISE;
if (dot(a, b) < -EPS)
return ONLINE_BACK;
if (a.norm() < b.norm())
return ONLINE_FRONT;
return ON_SEGMENT;
}
static bool intersect(Point p1, Point p2, Point p3, Point p4) {
return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 &&
ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0);
}
static bool intersect(Segment s1, Segment s2);
static Point project(Segment s, Point p);
static Point reflect(Segment s, Point p);
static Point getDistance(Point a, Point b) { return (a - b).abs(); }
static double getDistanceLP(Segment s, Point p);
static double getDistanceSP(Segment s, Point p);
static double getDistance(Segment s1, Segment s2);
static Point getIntersection(Segment s1, Segment s2);
static pair<Point, Point> crossPoints(Circle c, Segment s);
static int contains(vector<Point> g, Point p) {
int n = g.size();
bool x = false;
rep(i, n) {
Point a = g[i] - p, b = g[(i + 1) % n] - p;
// 線の上に載っているか
if (std::abs(cross(a, b)) < EPS && dot(a, b) < EPS)
return 1;
// pを基準として上下にあるか
// または外積が正か?(→にあるか)
if (a.y > b.y)
swap(a, b);
if (a.y < EPS && EPS < b.y && cross(a, b) > EPS)
x = !x;
}
return x ? 2 : 0;
}
static vector<Point> andrewScan(vector<Point> s) {
vector<Point> u, l;
if (s.size() < 3)
return s;
sort(all(s));
u.push_back(s[0]);
u.push_back(s[1]);
l.push_back(s[s.size() - 1]);
l.push_back(s[s.size() - 2]);
for (int i = 2; i < s.size(); i++) {
for (int _n = u.size();
_n >= 2 && ccw(u[_n - 2], u[_n - 1], s[i]) > CLOCKWISE; _n--) {
u.pop_back();
}
u.push_back(s[i]);
}
for (int i = s.size() - 3; i >= 0; i--) {
for (int _n = l.size();
_n >= 2 && ccw(l[_n - 2], l[_n - 1], s[i]) > CLOCKWISE; _n--) {
l.pop_back();
}
l.push_back(s[i]);
}
reverse(all(l));
for (int i = u.size() - 2; i >= 1; i--) {
l.push_back(u[i]);
}
return l;
}
void get_cin() { cin >> x >> y; }
};
class Segment {
public:
Point p1, p2;
Segment() {}
Segment(Point p1, Point p2) : p1(p1), p2(p2) {}
void get_cin() { cin >> p1.x >> p1.y >> p2.x >> p2.y; }
Point p1tp2() { return p2 - p1; }
Point p2tp1() { return p1 - p2; }
double abs() { return std::abs(norm()); }
double norm() { return (p2 - p1).norm(); }
};
bool Point::isOrthogonal(Segment s1, Segment s2) {
return EQ(dot(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}
bool Point::isPalallel(Segment s1, Segment s2) {
return EQ(cross(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}
bool Point::intersect(Segment s1, Segment s2) {
return intersect(s1.p1, s1.p2, s2.p1, s2.p2);
}
Point Point::project(Segment s, Point p) {
Point base = s.p2 - s.p1;
double r = Point::dot(p - s.p1, base) / base.norm();
return s.p1 + base * r;
}
Point Point::reflect(Segment s, Point p) { return (project(s, p) * 2) - p; }
double Point::getDistanceLP(Segment s, Point p) {
return std::abs(cross(s.p2 - s.p1, p - s.p1) / (s.p2 - s.p1).abs());
}
double Point::getDistanceSP(Segment s, Point p) {
if (dot(s.p2 - s.p1, p - s.p1) < 0.0)
return (p - s.p1).abs();
if (dot(s.p1 - s.p2, p - s.p2) < 0.0)
return (p - s.p2).abs();
return getDistanceLP(s, p);
}
double Point::getDistance(Segment s1, Segment s2) {
if (intersect(s1, s2))
return 0.0;
return min({getDistanceSP(s1, s2.p1), getDistanceSP(s1, s2.p2),
getDistanceSP(s2, s1.p1), getDistanceSP(s2, s1.p2)});
}
Point Point::getIntersection(Segment s1, Segment s2) {
// (s1.p1 - s2.p1).norm()
auto bs = s1.p2 - s1.p1;
auto n1 = s2.p1 - s1.p1;
auto n2 = s2.p2 - s1.p1;
auto c1 = std::abs(cross(n1, bs)) / bs.norm();
auto c2 = std::abs(cross(n2, bs)) / bs.norm();
return s2.p1 + (s2.p2 - s2.p1) * (c1 / (c1 + c2));
// c1:c2=t:1-t
// c2t=(1-t)c1
// t/(1-t)=c1/(c1+c2)
//
}
double arg(Point p) { return atan2(p.y, p.x); }
Point polar(double a, double r) { return Point(cos(r) * a, sin(r) * a); }
class Circle {
public:
Point c;
double r;
Circle(Point c = Point(), double r = 0.0) : c(c), r(r) {}
void get_cin() { cin >> c.x >> c.y >> r; }
static pair<Point, Point> getCrossPoints(Circle c1, Circle c2) {
double d = (c1.c - c2.c).abs(); // 中心点どうしの距離
double a = acos((c1.r * c1.r + d * d - c2.r * c2.r) / (2 * c1.r * d));
double t = arg(c2.c - c1.c);
return make_pair(c1.c + polar(c1.r, t + a), c1.c + polar(c1.r, t - a));
}
};
pair<Point, Point> Point::crossPoints(Circle c, Segment s) {
auto pp = project(s, c.c);
auto f = (pp - c.c).norm();
auto mu = sqrt(c.r * c.r - f);
auto e = s.p1tp2() / s.p1tp2().abs();
return make_pair(pp + e * mu, pp - e * mu);
}
ll divRm(string s, ll x) {
ll r = 0;
for (ll i = 0; i < s.size(); i++) {
r *= 10;
r += s[i] - '0';
r %= x;
}
return r;
}
ll cmbi(ll x, ll b) {
ll res = 1;
for (size_t i = 0; i < b; i++) {
res *= x - i;
res %= INF;
res *= inv[b - i];
res %= INF;
}
return res;
}
double digsum(ll x) {
ll res = 0;
while (x > 0) {
res += x % 10;
x /= 10;
}
return res;
}
bool check_parindrome(string s) {
int n = s.size();
rep(i, n / 2) {
if (s[i] != s[n - i - 1]) {
return false;
}
}
return true;
}
// ここまでライブラリ
// ここからコード
struct query {
ll col, d, i;
bool lca;
};
struct color {
ll c, d;
};
vector<vector<edge>> es;
ll c[100010], d[100010];
vector<query> Q[100010];
color co[100010];
ll ans[100010];
void eul(ll x, ll f, ll dis) {
for (auto v : Q[x]) {
ll val = dis - co[v.col].d + co[v.col].c * v.d;
if (v.lca) {
ans[v.i] -= val * 2;
} else {
ans[v.i] += val;
}
}
for (auto v : es[x]) {
if (v.to == f)
continue;
ll col = c[v.i];
ll di = d[v.i];
co[col].c++;
co[col].d += di;
eul(v.to, x, dis + di);
co[col].c--;
co[col].d -= di;
}
}
void solv() {
ll q;
cin >> n >> q;
es = vector<vector<edge>>(n + 1);
rep(i, n - 1) {
ll a, b;
cin >> a >> b >> c[i] >> d[i];
es[a].push_back({b, i});
es[b].push_back({a, i});
}
LCA lca(n, 1, es);
rep(i, q) {
ll x, y, u, v;
cin >> x >> y >> u >> v;
Q[u].push_back({x, y, i, false});
Q[v].push_back({x, y, i, false});
Q[lca.lca(u, v)].push_back({x, y, i, true});
}
eul(1, 0, 0);
rep(i, q) { cout << ans[i] << endl; }
}
int main() {
COMinit();
solv();
return 0;
}
| [
"assignment.change"
] | 793,189 | 793,190 | u224756887 | cpp |
p02986 | #include <algorithm>
#include <array>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctype.h>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <unordered_map>
#include <utility>
#include <vector>
#define _USE_MATH_DEFINES
#include <iostream>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, double> pld;
typedef pair<double, double> pdd;
typedef pair<double, ll> pdl;
typedef pair<int, char> pic;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef priority_queue<ll, vector<ll>, greater<ll>> llgreaterq;
typedef priority_queue<pll, vector<pll>, greater<pll>> pllgreaterq;
typedef priority_queue<pair<ll, pll>, vector<pair<ll, pll>>,
greater<pair<ll, pll>>>
plpllgreaterq;
typedef priority_queue<vi, vector<vi>, greater<vi>> vigreaterq;
typedef priority_queue<vl, vector<vl>, greater<vl>> vlgreaterq;
template <class o, class p, class q>
using tuple3q = priority_queue<tuple<o, p, q>, vector<tuple<o, p, q>>,
greater<tuple<o, p, q>>>;
template <class o, class p, class q, class r>
using tuple4q = priority_queue<tuple<o, p, q, r>, vector<tuple<o, p, q, r>>,
greater<tuple<o, p, q, r>>>;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
#define bit(x, v) ((ll)x << v)
#define rep(x, n) for (ll x = 0; x < n; x++)
#define rep2(x, f, v) for (ll x = f; x < v; x++)
#define repe(v, x) for (auto v : x)
// 許容する誤差ε
#define EPS (1e-10)
// 2つのスカラーが等しいかどうか
#define EQ(a, b) (std::abs(a - b) < EPS)
// 2つのベクトルが等しいかどうか
#define EQV(a, b) (EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()))
#define all(a) a.begin(), a.end()
#define all0(a) memset(a, 0, sizeof(a))
#define allm1(a) memset(a, -1, sizeof(a))
#define put_float(v) \
cout << fixed << setprecision(10); \
cout << v << endl
#define put(v) cout << v << endl
#define vinsert(v, p, x) v.insert(v.begin() + p, x)
#define vsort(v) sort(all(v));
#define dup(v) v.erase(unique(all(v)), v.end())
#define ion(i, j) ((i & (1LL << j)) > 0)
#define next(i) \
i++; \
i %= 2
#define Len size()
#define ull unsignd long long
#define psp(a, b) push_back(make_pair(a, b))
#define psp2(a, b) push(make_pair(a, b))
#define cini(a) \
a; \
cin >> a
#define infa(a, b) (a + b) % INF
#define infm(a, b) (a * b) % INF
#define infd(a, b) (a * modinv(b)) % INF
#define infs(a, b) (a + INF - b) % INF
#define inf(a) (a) %= INF
#define inff(a) ((a) % INF)
#define No cout << "No" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define YES cout << "YES" << endl
#define smal -INF *INF
#define big INF *INF
const ll INF = 1000000007;
const int MAX = 2000010;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll getpow(ll b, ll x, ll md) {
ll t = b;
ll res = 1;
while (x > 0) {
if (x & 1) {
res *= t;
res %= md;
}
x >>= 1;
t *= t;
t %= md;
}
return res;
}
ll getpow(ll b, ll x) { return getpow(b, x, INF); }
ll modinv(ll x) { return getpow(x, INF - 2); }
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
class mint {
int md = 1000000007;
public:
long long x;
mint(ll x, ll md) {
this->md = md;
this->x = (x % md + md) % md;
}
mint(long long x = 0) : x((x % md + md) % md) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint &a) {
if ((x += a.x) >= md)
x -= md;
return *this;
}
mint &operator-=(const mint &a) {
if ((x += md - a.x) >= md)
x -= md;
return *this;
}
mint &operator*=(const mint &a) {
(x *= a.x) %= md;
return *this;
}
mint operator+(const mint &a) const {
mint res(*this);
return res += a;
}
mint operator-(const mint &a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint &a) const {
mint res(*this);
return res *= a;
}
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(md - 2); }
mint &operator/=(const mint &a) { return (*this) *= a.inv(); }
mint operator/(const mint &a) const {
mint res(*this);
return res /= a;
}
friend ostream &operator<<(ostream &os, const mint &m) {
os << m.x;
return os;
}
};
int pr[100010];
int lank[100010];
void uini(int n) {
for (size_t i = 0; i <= n; i++) {
pr[i] = i;
lank[i] = 1;
}
}
int parent(int x) {
if (x == pr[x])
return x;
return pr[x] = parent(pr[x]);
}
int same(int x, int y) { return parent(x) == parent(y); }
bool unit(int x, int y) {
int px = parent(x);
int py = parent(y);
if (px == py)
return false;
if (lank[py] < lank[px]) {
pr[py] = px;
lank[px] += lank[py];
} else {
pr[px] = py;
lank[py] += lank[px];
}
return true;
}
ll n;
int ci = 0;
struct Node {
int key;
int priority;
Node *parent, *left, *right;
Node(int key, int priority);
Node() {}
};
Node NIL;
Node::Node(int key, int priority) : key(key), priority(priority) {
left = &NIL;
right = &NIL;
}
Node *root = new Node();
void cenrec(Node *k) {
if (k->key == NIL.key)
return;
cenrec(k->left);
cout << " " << k->key;
cenrec(k->right);
}
void fastrec(Node *k) {
if (k->key == NIL.key)
return;
cout << " " << k->key;
fastrec(k->left);
fastrec(k->right);
}
void insert(Node *v) {
Node *y = &NIL;
Node *x = root;
while (x->key != NIL.key) {
y = x;
if (v->key < x->key) {
x = x->left;
} else {
x = x->right;
}
}
v->parent = y;
if (y->key == NIL.key) {
root = v;
} else if (v->key < y->key) {
y->left = v;
} else {
y->right = v;
}
}
Node *find(Node *k, ll v) {
if (k->key == NIL.key)
return &NIL;
if (k->key == v)
return k;
if (v < k->key)
return find(k->left, v);
return find(k->right, v);
}
void delp12(Node *x) {
if (x->key == NIL.key)
return;
Node *l = x->left;
Node *r = x->right;
Node *pr = x->parent;
if (l->key == NIL.key && r->key == NIL.key) {
if (pr->left == x) {
pr->left = &NIL;
} else
pr->right = &NIL;
} else if (l->key != NIL.key) {
if (pr->left == x) {
pr->left = l;
} else
pr->right = l;
l->parent = pr;
} else if (r->key != NIL.key) {
if (pr->left == x) {
pr->left = r;
} else
pr->right = r;
r->parent = pr;
}
}
Node *get_next(Node *k) {
if (k->key == NIL.key)
return &NIL;
Node *res = get_next(k->left);
if (res->key != NIL.key)
return res;
return k;
}
void del(Node *x) {
if (x->key == NIL.key)
return;
Node *l = x->left;
Node *r = x->right;
Node *pr = x->parent;
if (l->key != NIL.key && r->key != NIL.key) {
Node *nex = get_next(r);
x->key = nex->key;
delp12(nex);
} else {
delp12(x);
}
}
Node *rightRotate(Node *t) {
Node *s = t->left;
t->left = s->right;
s->right = t;
return s;
}
Node *leftRotate(Node *t) {
Node *s = t->right;
t->right = s->left;
s->left = t;
return s;
}
Node *_insert(Node *t, int key, int priority) {
if (t->key == NIL.key) {
return new Node(key, priority);
}
if (key == t->key) {
return t;
}
if (key < t->key) {
t->left = _insert(t->left, key, priority);
if (t->priority < t->left->priority) {
t = rightRotate(t);
}
} else {
t->right = _insert(t->right, key, priority);
if (t->priority < t->right->priority) {
t = leftRotate(t);
}
}
return t;
}
Node *delete1(Node *t, int key);
Node *_delete(Node *t, int key) {
if (t->left->key == NIL.key && t->right->key == NIL.key) {
return &NIL;
} else if (t->left->key == NIL.key) {
t = leftRotate(t);
} else if (t->right->key == NIL.key) {
t = rightRotate(t);
} else {
if (t->left->priority > t->right->priority) {
t = rightRotate(t);
} else
t = leftRotate(t);
}
return delete1(t, key);
}
Node *delete1(Node *t, int key) {
if (t->key == NIL.key) {
return &NIL;
}
if (key < t->key) {
t->left = delete1(t->left, key);
} else if (key > t->key) {
t->right = delete1(t->right, key);
} else
return _delete(t, key);
return t;
}
int H;
int left(int i) { return i * 2 + 1; }
int right(int i) { return i * 2 + 2; }
class edge {
public:
int from, to, i;
ll val;
edge() {}
edge(ll to) : to(to) {}
edge(ll to, ll i) : to(to), i(i) {}
edge(ll from, ll to, ll val) : from(from), to(to), val(val) {}
};
class LCA {
private:
vector<vector<edge>> v;
vector<vector<int>> parent;
vector<int> depth;
void dfs(int n, int m, int d) {
parent[0][n] = m;
depth[n] = d;
for (auto x : v[n]) {
if (x.to != m)
dfs(x.to, n, d + 1);
}
}
public:
LCA(ll N, ll root, vector<vector<edge>> &tree) {
v = tree;
parent = vector<vector<int>>(21, vector<int>(N + 1, 0));
depth = vector<int>(N + 1, 0);
dfs(root, -1, 0);
for (int j = 0; j + 1 < 20; j++) {
for (int i = 1; i <= N; i++) {
if (parent[j][i] < 0)
parent[j + 1][i] = -1;
else
parent[j + 1][i] = parent[j][parent[j][i]];
}
}
}
int lca(int n, int m) {
if (depth[n] > depth[m])
swap(n, m);
for (int j = 0; j < 20; j++) {
if ((depth[m] - depth[n]) >> j & 1)
m = parent[j][m];
}
if (n == m)
return n;
for (int j = 19; j >= 0; j--) {
if (parent[j][n] != parent[j][m]) {
n = parent[j][n];
m = parent[j][m];
}
}
return parent[0][n];
}
int dep(int n) { return depth[n]; }
};
ll k;
int _rank[1010];
int temp[1010];
bool compare_sa(int i, int j) {
if (_rank[i] != _rank[j])
return _rank[i] < _rank[j];
else {
int ri = i + k <= n ? _rank[i + k] : -1;
int rj = j + k <= n ? _rank[j + k] : -1;
return ri < rj;
}
}
void construct_sa(string S, int *sa) {
n = S.length();
for (size_t i = 0; i <= n; i++) {
sa[i] = i;
_rank[i] = i < n ? S[i] : -1;
}
for (k = 1; k <= n; k *= 2) {
sort(sa, sa + n + 1, compare_sa);
// saはソート後の接尾辞の並びになっている、rankは元の位置のindexを保持したまま、更新されている。
// ピンとこなかった部分
temp[sa[0]] = 0;
for (size_t i = 1; i <= n; i++) {
temp[sa[i]] = temp[sa[i - 1]] + (compare_sa(sa[i - 1], sa[i]) ? 1 : 0);
}
for (size_t i = 0; i <= n; i++) {
_rank[i] = temp[i];
}
}
}
bool contain(string S, int *sa, string T) {
int a = 0, b = S.length();
// sa は 接尾辞が辞書順に並んでいる、入っているのはその位置のインデックス
while (b - a > 1) {
int c = (a + b) / 2;
if (S.compare(sa[c], T.length(), T) < 0)
a = c;
else
b = c;
}
return S.compare(sa[b], T.length(), T) == 0;
}
#define bit(x, v) ((ll)x << v)
class BIT {
static const int MAX_N = 500010;
public:
BIT() { memset(bit, 0, sizeof(bit)); }
ll bit[MAX_N + 1], n;
ll sum(int i) {
ll s = 0;
while (i > 0) {
s += bit[i];
i -= i & -i;
}
return s;
}
void add(int i, int x) {
while (i <= n) {
bit[i] += x;
i += i & -i;
}
}
};
struct UnionFind {
vector<int> A;
UnionFind(int n) : A(n, -1) {}
int find(int x) {
if (A[x] < 0)
return x;
return A[x] = find(A[x]);
}
void unite(int x, int y) {
x = find(x), y = find(y);
if (x == y)
return;
if (A[x] > A[y])
swap(x, y);
A[x] += A[y];
A[y] = x;
}
int ngroups() {
int ans = 0;
for (auto a : A)
if (a < 0)
ans++;
return ans;
}
};
vector<ll> getp(ll n) {
vector<ll> res;
ll a = 2;
if (n % 2 == 0) {
res.push_back(2);
while (n % 2 == 0)
n /= 2;
}
for (ll i = 3; i * i <= n; i += 2) {
if (n % i == 0) {
res.push_back(i);
while (n % i == 0)
n /= i;
}
}
if (n != 1)
res.push_back(n);
return res;
}
vector<ll> getp2(ll n) {
vector<ll> res;
ll a = 2;
if (n % 2 == 0) {
while (n % 2 == 0) {
n /= 2;
res.push_back(2);
}
}
for (ll i = 3; i * i <= n; i += 2) {
if (n % i == 0) {
while (n % i == 0) {
n /= i;
res.push_back(i);
}
}
}
if (n != 1)
res.push_back(n);
return res;
}
vector<pll> getp3(ll n) {
vector<pll> res;
ll a = 2;
int si = 0;
if (n % 2 == 0) {
res.push_back(make_pair(2, 0));
while (n % 2 == 0) {
n /= 2;
res[si].second++;
}
si++;
}
for (ll i = 3; i * i <= n; i += 2) {
if (n % i == 0) {
res.push_back(make_pair(i, 0));
while (n % i == 0) {
n /= i;
res[si].second++;
}
si++;
}
}
if (n != 1) {
res.push_back(make_pair(n, 1));
}
return res;
}
vector<ll> getDivisors(ll n) {
vector<ll> res;
ll a = 2;
res.push_back(1);
for (ll i = 2; i * i <= n; i++) {
if (n % i == 0) {
res.push_back(i);
if (n / i != i)
res.push_back(n / i);
}
}
return res;
}
struct ve {
public:
vector<ve> child;
int _t = INF;
ve(int t) : _t(t) {}
ve(ve _left, ve _right) {
_t = _left._t + _right._t;
child.push_back(_left);
child.push_back(_right);
}
bool operator<(const ve &t) const { return _t > t._t; }
};
vector<bool> elas(ll n) {
vector<bool> r(n);
fill(r.begin(), r.end(), 1);
r[0] = 0;
r[1] = 0;
for (ll i = 2; i * i < n; i++) {
if (!r[i])
continue;
ll ti = i * 2;
while (ti < n) {
r[ti] = false;
ti += i;
}
}
return r;
}
bool isPrime(ll v) {
for (ll i = 2; i * i <= v; i++) {
if (v % i == 0)
return false;
}
return true;
}
class SegTree {
public:
const static int MAX_N = 100010;
const static int DAT_SIZE = (1 << 18) - 1;
int N, Q;
int A[MAX_N];
ll data[DAT_SIZE], datb[DAT_SIZE];
void init(int _n) {
N = 1;
while (N < _n)
N <<= 1;
memset(data, 0, sizeof(data));
memset(datb, 0, sizeof(datb));
}
void init(int _n, ll iv) {
N = 1;
while (N < _n)
N <<= 1;
rep(i, DAT_SIZE) {
data[i] = iv;
datb[i] = iv;
}
}
void add(int a, int b, int x) { add(a, b + 1, x, 0, 0, N); }
void add(int a, int b, int x, int k, int l, int r) {
if (a <= l && r <= b) {
data[k] += x;
} else if (l < b && a < r) {
datb[k] += (min(b, r) - max(a, l)) * x;
add(a, b, x, k * 2 + 1, l, (l + r) / 2);
add(a, b, x, k * 2 + 2, (l + r) / 2, r);
}
}
void change(int a, int b, int x) { change(a, b + 1, x, 0, 0, N); }
void change(int a, int b, int x, int k, int l, int r) {
if (a <= l && r <= b) {
data[k] = x;
} else if (l < b && a < r) {
datb[k] = x;
change(a, b, x, k * 2 + 1, l, (l + r) / 2);
change(a, b, x, k * 2 + 2, (l + r) / 2, r);
}
}
ll sum(int a, int b) { return sum(a, b + 1, 0, 0, N); }
ll sum(int a, int b, int k, int l, int r) {
if (b <= l || r <= a) {
return 0;
}
if (a <= l && r <= b) {
return data[k] * (r - l) + datb[k];
}
ll res = (min(b, r) - max(a, l)) * data[k];
res += sum(a, b, k * 2 + 1, l, (l + r) / 2);
res += sum(a, b, k * 2 + 2, (l + r) / 2, r);
return res;
}
};
class Segment;
class Circle;
class Point {
public:
double x, y;
Point(double x = 0, double y = 0) : x(x), y(y) {}
Point operator+(Point p) { return Point(x + p.x, y + p.y); }
Point operator-(Point p) { return Point(x - p.x, y - p.y); }
Point operator*(double a) { return Point(a * x, a * y); }
Point operator/(double a) { return Point(x / a, y / a); }
double abs() { return sqrt(norm()); }
double norm() { return x * x + y * y; }
bool operator<(const Point &p) const { return x != p.x ? x < p.x : y < p.y; }
bool operator==(const Point &p) const {
return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
}
static double dot(Point a, Point b) { return a.x * b.x + a.y * b.y; }
static double cross(Point a, Point b) { return a.x * b.y - a.y * b.x; }
static bool isOrthogonal(Point a, Point b) { return EQ(dot(a, b), 0.0); }
static bool isOrthogonal(Point a1, Point a2, Point b1, Point b2) {
return isOrthogonal(a1 - a2, b1 - b2);
}
static bool isOrthogonal(Segment s1, Segment s2);
static bool isPalallel(Point a, Point b) { return EQ(cross(a, b), 0.0); }
static bool isPalallel(Point a1, Point a2, Point b1, Point b2) {
return isPalallel(a1 - a2, b1 - b2);
}
static bool isPalallel(Segment s1, Segment s2);
static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;
static int ccw(Point p0, Point p1, Point p2) {
// 線分はp0とp1でp2がどこにあるかを探る
Point a = p1 - p0;
Point b = p2 - p0;
if (cross(a, b) > EPS)
return COUNTER_CLOCKWISE;
if (cross(a, b) < -EPS)
return CLOCKWISE;
if (dot(a, b) < -EPS)
return ONLINE_BACK;
if (a.norm() < b.norm())
return ONLINE_FRONT;
return ON_SEGMENT;
}
static bool intersect(Point p1, Point p2, Point p3, Point p4) {
return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 &&
ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0);
}
static bool intersect(Segment s1, Segment s2);
static Point project(Segment s, Point p);
static Point reflect(Segment s, Point p);
static Point getDistance(Point a, Point b) { return (a - b).abs(); }
static double getDistanceLP(Segment s, Point p);
static double getDistanceSP(Segment s, Point p);
static double getDistance(Segment s1, Segment s2);
static Point getIntersection(Segment s1, Segment s2);
static pair<Point, Point> crossPoints(Circle c, Segment s);
static int contains(vector<Point> g, Point p) {
int n = g.size();
bool x = false;
rep(i, n) {
Point a = g[i] - p, b = g[(i + 1) % n] - p;
// 線の上に載っているか
if (std::abs(cross(a, b)) < EPS && dot(a, b) < EPS)
return 1;
// pを基準として上下にあるか
// または外積が正か?(→にあるか)
if (a.y > b.y)
swap(a, b);
if (a.y < EPS && EPS < b.y && cross(a, b) > EPS)
x = !x;
}
return x ? 2 : 0;
}
static vector<Point> andrewScan(vector<Point> s) {
vector<Point> u, l;
if (s.size() < 3)
return s;
sort(all(s));
u.push_back(s[0]);
u.push_back(s[1]);
l.push_back(s[s.size() - 1]);
l.push_back(s[s.size() - 2]);
for (int i = 2; i < s.size(); i++) {
for (int _n = u.size();
_n >= 2 && ccw(u[_n - 2], u[_n - 1], s[i]) > CLOCKWISE; _n--) {
u.pop_back();
}
u.push_back(s[i]);
}
for (int i = s.size() - 3; i >= 0; i--) {
for (int _n = l.size();
_n >= 2 && ccw(l[_n - 2], l[_n - 1], s[i]) > CLOCKWISE; _n--) {
l.pop_back();
}
l.push_back(s[i]);
}
reverse(all(l));
for (int i = u.size() - 2; i >= 1; i--) {
l.push_back(u[i]);
}
return l;
}
void get_cin() { cin >> x >> y; }
};
class Segment {
public:
Point p1, p2;
Segment() {}
Segment(Point p1, Point p2) : p1(p1), p2(p2) {}
void get_cin() { cin >> p1.x >> p1.y >> p2.x >> p2.y; }
Point p1tp2() { return p2 - p1; }
Point p2tp1() { return p1 - p2; }
double abs() { return std::abs(norm()); }
double norm() { return (p2 - p1).norm(); }
};
bool Point::isOrthogonal(Segment s1, Segment s2) {
return EQ(dot(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}
bool Point::isPalallel(Segment s1, Segment s2) {
return EQ(cross(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}
bool Point::intersect(Segment s1, Segment s2) {
return intersect(s1.p1, s1.p2, s2.p1, s2.p2);
}
Point Point::project(Segment s, Point p) {
Point base = s.p2 - s.p1;
double r = Point::dot(p - s.p1, base) / base.norm();
return s.p1 + base * r;
}
Point Point::reflect(Segment s, Point p) { return (project(s, p) * 2) - p; }
double Point::getDistanceLP(Segment s, Point p) {
return std::abs(cross(s.p2 - s.p1, p - s.p1) / (s.p2 - s.p1).abs());
}
double Point::getDistanceSP(Segment s, Point p) {
if (dot(s.p2 - s.p1, p - s.p1) < 0.0)
return (p - s.p1).abs();
if (dot(s.p1 - s.p2, p - s.p2) < 0.0)
return (p - s.p2).abs();
return getDistanceLP(s, p);
}
double Point::getDistance(Segment s1, Segment s2) {
if (intersect(s1, s2))
return 0.0;
return min({getDistanceSP(s1, s2.p1), getDistanceSP(s1, s2.p2),
getDistanceSP(s2, s1.p1), getDistanceSP(s2, s1.p2)});
}
Point Point::getIntersection(Segment s1, Segment s2) {
// (s1.p1 - s2.p1).norm()
auto bs = s1.p2 - s1.p1;
auto n1 = s2.p1 - s1.p1;
auto n2 = s2.p2 - s1.p1;
auto c1 = std::abs(cross(n1, bs)) / bs.norm();
auto c2 = std::abs(cross(n2, bs)) / bs.norm();
return s2.p1 + (s2.p2 - s2.p1) * (c1 / (c1 + c2));
// c1:c2=t:1-t
// c2t=(1-t)c1
// t/(1-t)=c1/(c1+c2)
//
}
double arg(Point p) { return atan2(p.y, p.x); }
Point polar(double a, double r) { return Point(cos(r) * a, sin(r) * a); }
class Circle {
public:
Point c;
double r;
Circle(Point c = Point(), double r = 0.0) : c(c), r(r) {}
void get_cin() { cin >> c.x >> c.y >> r; }
static pair<Point, Point> getCrossPoints(Circle c1, Circle c2) {
double d = (c1.c - c2.c).abs(); // 中心点どうしの距離
double a = acos((c1.r * c1.r + d * d - c2.r * c2.r) / (2 * c1.r * d));
double t = arg(c2.c - c1.c);
return make_pair(c1.c + polar(c1.r, t + a), c1.c + polar(c1.r, t - a));
}
};
pair<Point, Point> Point::crossPoints(Circle c, Segment s) {
auto pp = project(s, c.c);
auto f = (pp - c.c).norm();
auto mu = sqrt(c.r * c.r - f);
auto e = s.p1tp2() / s.p1tp2().abs();
return make_pair(pp + e * mu, pp - e * mu);
}
ll divRm(string s, ll x) {
ll r = 0;
for (ll i = 0; i < s.size(); i++) {
r *= 10;
r += s[i] - '0';
r %= x;
}
return r;
}
ll cmbi(ll x, ll b) {
ll res = 1;
for (size_t i = 0; i < b; i++) {
res *= x - i;
res %= INF;
res *= inv[b - i];
res %= INF;
}
return res;
}
double digsum(ll x) {
ll res = 0;
while (x > 0) {
res += x % 10;
x /= 10;
}
return res;
}
bool check_parindrome(string s) {
int n = s.size();
rep(i, n / 2) {
if (s[i] != s[n - i - 1]) {
return false;
}
}
return true;
}
// ここまでライブラリ
// ここからコード
vector<vector<edge>> es;
ll col[100010], dis[100010];
ll ans[100010];
struct query {
ll c, d, i;
bool lca;
};
vector<query> Q[100010]; // 頂点に対してどのqueryがあるか
pll colr[100010];
void euler(ll x, ll f, ll d) {
for (auto v : Q[x]) {
ll val = d - colr[v.c].second + colr[v.c].first * v.d;
if (v.lca) {
ans[v.i] -= val;
} else {
ans[v.i] += val;
}
}
for (auto v : es[x]) {
if (v.to == f)
continue;
int color = col[v.i];
colr[color].first++;
colr[color].second += dis[v.i];
euler(v.to, x, d + dis[v.i]);
colr[color].first--;
colr[color].second -= dis[v.i];
}
}
void solv() {
ll q;
cin >> n >> q;
es = vector<vector<edge>>(n + 1);
rep(i, n - 1) {
ll a, b;
cin >> a >> b >> col[i] >> dis[i];
es[a].push_back(edge(b, i));
es[b].push_back(edge(a, i));
}
LCA lca(n, 1, es);
rep(i, q) {
ll x, y, u, v;
cin >> x >> y >> u >> v;
Q[u].push_back({x, y, i, false});
Q[v].push_back({x, y, i, false});
Q[lca.lca(u, v)].push_back({x, y, i, true});
}
euler(1, 0, 0);
rep(i, q) { cout << ans[i] << endl; }
}
int main() {
COMinit();
solv();
return 0;
}
| #include <algorithm>
#include <array>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctype.h>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <unordered_map>
#include <utility>
#include <vector>
#define _USE_MATH_DEFINES
#include <iostream>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, double> pld;
typedef pair<double, double> pdd;
typedef pair<double, ll> pdl;
typedef pair<int, char> pic;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef priority_queue<ll, vector<ll>, greater<ll>> llgreaterq;
typedef priority_queue<pll, vector<pll>, greater<pll>> pllgreaterq;
typedef priority_queue<pair<ll, pll>, vector<pair<ll, pll>>,
greater<pair<ll, pll>>>
plpllgreaterq;
typedef priority_queue<vi, vector<vi>, greater<vi>> vigreaterq;
typedef priority_queue<vl, vector<vl>, greater<vl>> vlgreaterq;
template <class o, class p, class q>
using tuple3q = priority_queue<tuple<o, p, q>, vector<tuple<o, p, q>>,
greater<tuple<o, p, q>>>;
template <class o, class p, class q, class r>
using tuple4q = priority_queue<tuple<o, p, q, r>, vector<tuple<o, p, q, r>>,
greater<tuple<o, p, q, r>>>;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
#define bit(x, v) ((ll)x << v)
#define rep(x, n) for (ll x = 0; x < n; x++)
#define rep2(x, f, v) for (ll x = f; x < v; x++)
#define repe(v, x) for (auto v : x)
// 許容する誤差ε
#define EPS (1e-10)
// 2つのスカラーが等しいかどうか
#define EQ(a, b) (std::abs(a - b) < EPS)
// 2つのベクトルが等しいかどうか
#define EQV(a, b) (EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()))
#define all(a) a.begin(), a.end()
#define all0(a) memset(a, 0, sizeof(a))
#define allm1(a) memset(a, -1, sizeof(a))
#define put_float(v) \
cout << fixed << setprecision(10); \
cout << v << endl
#define put(v) cout << v << endl
#define vinsert(v, p, x) v.insert(v.begin() + p, x)
#define vsort(v) sort(all(v));
#define dup(v) v.erase(unique(all(v)), v.end())
#define ion(i, j) ((i & (1LL << j)) > 0)
#define next(i) \
i++; \
i %= 2
#define Len size()
#define ull unsignd long long
#define psp(a, b) push_back(make_pair(a, b))
#define psp2(a, b) push(make_pair(a, b))
#define cini(a) \
a; \
cin >> a
#define infa(a, b) (a + b) % INF
#define infm(a, b) (a * b) % INF
#define infd(a, b) (a * modinv(b)) % INF
#define infs(a, b) (a + INF - b) % INF
#define inf(a) (a) %= INF
#define inff(a) ((a) % INF)
#define No cout << "No" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define YES cout << "YES" << endl
#define smal -INF *INF
#define big INF *INF
const ll INF = 1000000007;
const int MAX = 2000010;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll getpow(ll b, ll x, ll md) {
ll t = b;
ll res = 1;
while (x > 0) {
if (x & 1) {
res *= t;
res %= md;
}
x >>= 1;
t *= t;
t %= md;
}
return res;
}
ll getpow(ll b, ll x) { return getpow(b, x, INF); }
ll modinv(ll x) { return getpow(x, INF - 2); }
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
class mint {
int md = 1000000007;
public:
long long x;
mint(ll x, ll md) {
this->md = md;
this->x = (x % md + md) % md;
}
mint(long long x = 0) : x((x % md + md) % md) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint &a) {
if ((x += a.x) >= md)
x -= md;
return *this;
}
mint &operator-=(const mint &a) {
if ((x += md - a.x) >= md)
x -= md;
return *this;
}
mint &operator*=(const mint &a) {
(x *= a.x) %= md;
return *this;
}
mint operator+(const mint &a) const {
mint res(*this);
return res += a;
}
mint operator-(const mint &a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint &a) const {
mint res(*this);
return res *= a;
}
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(md - 2); }
mint &operator/=(const mint &a) { return (*this) *= a.inv(); }
mint operator/(const mint &a) const {
mint res(*this);
return res /= a;
}
friend ostream &operator<<(ostream &os, const mint &m) {
os << m.x;
return os;
}
};
int pr[100010];
int lank[100010];
void uini(int n) {
for (size_t i = 0; i <= n; i++) {
pr[i] = i;
lank[i] = 1;
}
}
int parent(int x) {
if (x == pr[x])
return x;
return pr[x] = parent(pr[x]);
}
int same(int x, int y) { return parent(x) == parent(y); }
bool unit(int x, int y) {
int px = parent(x);
int py = parent(y);
if (px == py)
return false;
if (lank[py] < lank[px]) {
pr[py] = px;
lank[px] += lank[py];
} else {
pr[px] = py;
lank[py] += lank[px];
}
return true;
}
ll n;
int ci = 0;
struct Node {
int key;
int priority;
Node *parent, *left, *right;
Node(int key, int priority);
Node() {}
};
Node NIL;
Node::Node(int key, int priority) : key(key), priority(priority) {
left = &NIL;
right = &NIL;
}
Node *root = new Node();
void cenrec(Node *k) {
if (k->key == NIL.key)
return;
cenrec(k->left);
cout << " " << k->key;
cenrec(k->right);
}
void fastrec(Node *k) {
if (k->key == NIL.key)
return;
cout << " " << k->key;
fastrec(k->left);
fastrec(k->right);
}
void insert(Node *v) {
Node *y = &NIL;
Node *x = root;
while (x->key != NIL.key) {
y = x;
if (v->key < x->key) {
x = x->left;
} else {
x = x->right;
}
}
v->parent = y;
if (y->key == NIL.key) {
root = v;
} else if (v->key < y->key) {
y->left = v;
} else {
y->right = v;
}
}
Node *find(Node *k, ll v) {
if (k->key == NIL.key)
return &NIL;
if (k->key == v)
return k;
if (v < k->key)
return find(k->left, v);
return find(k->right, v);
}
void delp12(Node *x) {
if (x->key == NIL.key)
return;
Node *l = x->left;
Node *r = x->right;
Node *pr = x->parent;
if (l->key == NIL.key && r->key == NIL.key) {
if (pr->left == x) {
pr->left = &NIL;
} else
pr->right = &NIL;
} else if (l->key != NIL.key) {
if (pr->left == x) {
pr->left = l;
} else
pr->right = l;
l->parent = pr;
} else if (r->key != NIL.key) {
if (pr->left == x) {
pr->left = r;
} else
pr->right = r;
r->parent = pr;
}
}
Node *get_next(Node *k) {
if (k->key == NIL.key)
return &NIL;
Node *res = get_next(k->left);
if (res->key != NIL.key)
return res;
return k;
}
void del(Node *x) {
if (x->key == NIL.key)
return;
Node *l = x->left;
Node *r = x->right;
Node *pr = x->parent;
if (l->key != NIL.key && r->key != NIL.key) {
Node *nex = get_next(r);
x->key = nex->key;
delp12(nex);
} else {
delp12(x);
}
}
Node *rightRotate(Node *t) {
Node *s = t->left;
t->left = s->right;
s->right = t;
return s;
}
Node *leftRotate(Node *t) {
Node *s = t->right;
t->right = s->left;
s->left = t;
return s;
}
Node *_insert(Node *t, int key, int priority) {
if (t->key == NIL.key) {
return new Node(key, priority);
}
if (key == t->key) {
return t;
}
if (key < t->key) {
t->left = _insert(t->left, key, priority);
if (t->priority < t->left->priority) {
t = rightRotate(t);
}
} else {
t->right = _insert(t->right, key, priority);
if (t->priority < t->right->priority) {
t = leftRotate(t);
}
}
return t;
}
Node *delete1(Node *t, int key);
Node *_delete(Node *t, int key) {
if (t->left->key == NIL.key && t->right->key == NIL.key) {
return &NIL;
} else if (t->left->key == NIL.key) {
t = leftRotate(t);
} else if (t->right->key == NIL.key) {
t = rightRotate(t);
} else {
if (t->left->priority > t->right->priority) {
t = rightRotate(t);
} else
t = leftRotate(t);
}
return delete1(t, key);
}
Node *delete1(Node *t, int key) {
if (t->key == NIL.key) {
return &NIL;
}
if (key < t->key) {
t->left = delete1(t->left, key);
} else if (key > t->key) {
t->right = delete1(t->right, key);
} else
return _delete(t, key);
return t;
}
int H;
int left(int i) { return i * 2 + 1; }
int right(int i) { return i * 2 + 2; }
class edge {
public:
int from, to, i;
ll val;
edge() {}
edge(ll to) : to(to) {}
edge(ll to, ll i) : to(to), i(i) {}
edge(ll from, ll to, ll val) : from(from), to(to), val(val) {}
};
class LCA {
private:
vector<vector<edge>> v;
vector<vector<int>> parent;
vector<int> depth;
void dfs(int n, int m, int d) {
parent[0][n] = m;
depth[n] = d;
for (auto x : v[n]) {
if (x.to != m)
dfs(x.to, n, d + 1);
}
}
public:
LCA(ll N, ll root, vector<vector<edge>> &tree) {
v = tree;
parent = vector<vector<int>>(21, vector<int>(N + 1, 0));
depth = vector<int>(N + 1, 0);
dfs(root, -1, 0);
for (int j = 0; j + 1 < 20; j++) {
for (int i = 1; i <= N; i++) {
if (parent[j][i] < 0)
parent[j + 1][i] = -1;
else
parent[j + 1][i] = parent[j][parent[j][i]];
}
}
}
int lca(int n, int m) {
if (depth[n] > depth[m])
swap(n, m);
for (int j = 0; j < 20; j++) {
if ((depth[m] - depth[n]) >> j & 1)
m = parent[j][m];
}
if (n == m)
return n;
for (int j = 19; j >= 0; j--) {
if (parent[j][n] != parent[j][m]) {
n = parent[j][n];
m = parent[j][m];
}
}
return parent[0][n];
}
int dep(int n) { return depth[n]; }
};
ll k;
int _rank[1010];
int temp[1010];
bool compare_sa(int i, int j) {
if (_rank[i] != _rank[j])
return _rank[i] < _rank[j];
else {
int ri = i + k <= n ? _rank[i + k] : -1;
int rj = j + k <= n ? _rank[j + k] : -1;
return ri < rj;
}
}
void construct_sa(string S, int *sa) {
n = S.length();
for (size_t i = 0; i <= n; i++) {
sa[i] = i;
_rank[i] = i < n ? S[i] : -1;
}
for (k = 1; k <= n; k *= 2) {
sort(sa, sa + n + 1, compare_sa);
// saはソート後の接尾辞の並びになっている、rankは元の位置のindexを保持したまま、更新されている。
// ピンとこなかった部分
temp[sa[0]] = 0;
for (size_t i = 1; i <= n; i++) {
temp[sa[i]] = temp[sa[i - 1]] + (compare_sa(sa[i - 1], sa[i]) ? 1 : 0);
}
for (size_t i = 0; i <= n; i++) {
_rank[i] = temp[i];
}
}
}
bool contain(string S, int *sa, string T) {
int a = 0, b = S.length();
// sa は 接尾辞が辞書順に並んでいる、入っているのはその位置のインデックス
while (b - a > 1) {
int c = (a + b) / 2;
if (S.compare(sa[c], T.length(), T) < 0)
a = c;
else
b = c;
}
return S.compare(sa[b], T.length(), T) == 0;
}
#define bit(x, v) ((ll)x << v)
class BIT {
static const int MAX_N = 500010;
public:
BIT() { memset(bit, 0, sizeof(bit)); }
ll bit[MAX_N + 1], n;
ll sum(int i) {
ll s = 0;
while (i > 0) {
s += bit[i];
i -= i & -i;
}
return s;
}
void add(int i, int x) {
while (i <= n) {
bit[i] += x;
i += i & -i;
}
}
};
struct UnionFind {
vector<int> A;
UnionFind(int n) : A(n, -1) {}
int find(int x) {
if (A[x] < 0)
return x;
return A[x] = find(A[x]);
}
void unite(int x, int y) {
x = find(x), y = find(y);
if (x == y)
return;
if (A[x] > A[y])
swap(x, y);
A[x] += A[y];
A[y] = x;
}
int ngroups() {
int ans = 0;
for (auto a : A)
if (a < 0)
ans++;
return ans;
}
};
vector<ll> getp(ll n) {
vector<ll> res;
ll a = 2;
if (n % 2 == 0) {
res.push_back(2);
while (n % 2 == 0)
n /= 2;
}
for (ll i = 3; i * i <= n; i += 2) {
if (n % i == 0) {
res.push_back(i);
while (n % i == 0)
n /= i;
}
}
if (n != 1)
res.push_back(n);
return res;
}
vector<ll> getp2(ll n) {
vector<ll> res;
ll a = 2;
if (n % 2 == 0) {
while (n % 2 == 0) {
n /= 2;
res.push_back(2);
}
}
for (ll i = 3; i * i <= n; i += 2) {
if (n % i == 0) {
while (n % i == 0) {
n /= i;
res.push_back(i);
}
}
}
if (n != 1)
res.push_back(n);
return res;
}
vector<pll> getp3(ll n) {
vector<pll> res;
ll a = 2;
int si = 0;
if (n % 2 == 0) {
res.push_back(make_pair(2, 0));
while (n % 2 == 0) {
n /= 2;
res[si].second++;
}
si++;
}
for (ll i = 3; i * i <= n; i += 2) {
if (n % i == 0) {
res.push_back(make_pair(i, 0));
while (n % i == 0) {
n /= i;
res[si].second++;
}
si++;
}
}
if (n != 1) {
res.push_back(make_pair(n, 1));
}
return res;
}
vector<ll> getDivisors(ll n) {
vector<ll> res;
ll a = 2;
res.push_back(1);
for (ll i = 2; i * i <= n; i++) {
if (n % i == 0) {
res.push_back(i);
if (n / i != i)
res.push_back(n / i);
}
}
return res;
}
struct ve {
public:
vector<ve> child;
int _t = INF;
ve(int t) : _t(t) {}
ve(ve _left, ve _right) {
_t = _left._t + _right._t;
child.push_back(_left);
child.push_back(_right);
}
bool operator<(const ve &t) const { return _t > t._t; }
};
vector<bool> elas(ll n) {
vector<bool> r(n);
fill(r.begin(), r.end(), 1);
r[0] = 0;
r[1] = 0;
for (ll i = 2; i * i < n; i++) {
if (!r[i])
continue;
ll ti = i * 2;
while (ti < n) {
r[ti] = false;
ti += i;
}
}
return r;
}
bool isPrime(ll v) {
for (ll i = 2; i * i <= v; i++) {
if (v % i == 0)
return false;
}
return true;
}
class SegTree {
public:
const static int MAX_N = 100010;
const static int DAT_SIZE = (1 << 18) - 1;
int N, Q;
int A[MAX_N];
ll data[DAT_SIZE], datb[DAT_SIZE];
void init(int _n) {
N = 1;
while (N < _n)
N <<= 1;
memset(data, 0, sizeof(data));
memset(datb, 0, sizeof(datb));
}
void init(int _n, ll iv) {
N = 1;
while (N < _n)
N <<= 1;
rep(i, DAT_SIZE) {
data[i] = iv;
datb[i] = iv;
}
}
void add(int a, int b, int x) { add(a, b + 1, x, 0, 0, N); }
void add(int a, int b, int x, int k, int l, int r) {
if (a <= l && r <= b) {
data[k] += x;
} else if (l < b && a < r) {
datb[k] += (min(b, r) - max(a, l)) * x;
add(a, b, x, k * 2 + 1, l, (l + r) / 2);
add(a, b, x, k * 2 + 2, (l + r) / 2, r);
}
}
void change(int a, int b, int x) { change(a, b + 1, x, 0, 0, N); }
void change(int a, int b, int x, int k, int l, int r) {
if (a <= l && r <= b) {
data[k] = x;
} else if (l < b && a < r) {
datb[k] = x;
change(a, b, x, k * 2 + 1, l, (l + r) / 2);
change(a, b, x, k * 2 + 2, (l + r) / 2, r);
}
}
ll sum(int a, int b) { return sum(a, b + 1, 0, 0, N); }
ll sum(int a, int b, int k, int l, int r) {
if (b <= l || r <= a) {
return 0;
}
if (a <= l && r <= b) {
return data[k] * (r - l) + datb[k];
}
ll res = (min(b, r) - max(a, l)) * data[k];
res += sum(a, b, k * 2 + 1, l, (l + r) / 2);
res += sum(a, b, k * 2 + 2, (l + r) / 2, r);
return res;
}
};
class Segment;
class Circle;
class Point {
public:
double x, y;
Point(double x = 0, double y = 0) : x(x), y(y) {}
Point operator+(Point p) { return Point(x + p.x, y + p.y); }
Point operator-(Point p) { return Point(x - p.x, y - p.y); }
Point operator*(double a) { return Point(a * x, a * y); }
Point operator/(double a) { return Point(x / a, y / a); }
double abs() { return sqrt(norm()); }
double norm() { return x * x + y * y; }
bool operator<(const Point &p) const { return x != p.x ? x < p.x : y < p.y; }
bool operator==(const Point &p) const {
return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
}
static double dot(Point a, Point b) { return a.x * b.x + a.y * b.y; }
static double cross(Point a, Point b) { return a.x * b.y - a.y * b.x; }
static bool isOrthogonal(Point a, Point b) { return EQ(dot(a, b), 0.0); }
static bool isOrthogonal(Point a1, Point a2, Point b1, Point b2) {
return isOrthogonal(a1 - a2, b1 - b2);
}
static bool isOrthogonal(Segment s1, Segment s2);
static bool isPalallel(Point a, Point b) { return EQ(cross(a, b), 0.0); }
static bool isPalallel(Point a1, Point a2, Point b1, Point b2) {
return isPalallel(a1 - a2, b1 - b2);
}
static bool isPalallel(Segment s1, Segment s2);
static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;
static int ccw(Point p0, Point p1, Point p2) {
// 線分はp0とp1でp2がどこにあるかを探る
Point a = p1 - p0;
Point b = p2 - p0;
if (cross(a, b) > EPS)
return COUNTER_CLOCKWISE;
if (cross(a, b) < -EPS)
return CLOCKWISE;
if (dot(a, b) < -EPS)
return ONLINE_BACK;
if (a.norm() < b.norm())
return ONLINE_FRONT;
return ON_SEGMENT;
}
static bool intersect(Point p1, Point p2, Point p3, Point p4) {
return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 &&
ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0);
}
static bool intersect(Segment s1, Segment s2);
static Point project(Segment s, Point p);
static Point reflect(Segment s, Point p);
static Point getDistance(Point a, Point b) { return (a - b).abs(); }
static double getDistanceLP(Segment s, Point p);
static double getDistanceSP(Segment s, Point p);
static double getDistance(Segment s1, Segment s2);
static Point getIntersection(Segment s1, Segment s2);
static pair<Point, Point> crossPoints(Circle c, Segment s);
static int contains(vector<Point> g, Point p) {
int n = g.size();
bool x = false;
rep(i, n) {
Point a = g[i] - p, b = g[(i + 1) % n] - p;
// 線の上に載っているか
if (std::abs(cross(a, b)) < EPS && dot(a, b) < EPS)
return 1;
// pを基準として上下にあるか
// または外積が正か?(→にあるか)
if (a.y > b.y)
swap(a, b);
if (a.y < EPS && EPS < b.y && cross(a, b) > EPS)
x = !x;
}
return x ? 2 : 0;
}
static vector<Point> andrewScan(vector<Point> s) {
vector<Point> u, l;
if (s.size() < 3)
return s;
sort(all(s));
u.push_back(s[0]);
u.push_back(s[1]);
l.push_back(s[s.size() - 1]);
l.push_back(s[s.size() - 2]);
for (int i = 2; i < s.size(); i++) {
for (int _n = u.size();
_n >= 2 && ccw(u[_n - 2], u[_n - 1], s[i]) > CLOCKWISE; _n--) {
u.pop_back();
}
u.push_back(s[i]);
}
for (int i = s.size() - 3; i >= 0; i--) {
for (int _n = l.size();
_n >= 2 && ccw(l[_n - 2], l[_n - 1], s[i]) > CLOCKWISE; _n--) {
l.pop_back();
}
l.push_back(s[i]);
}
reverse(all(l));
for (int i = u.size() - 2; i >= 1; i--) {
l.push_back(u[i]);
}
return l;
}
void get_cin() { cin >> x >> y; }
};
class Segment {
public:
Point p1, p2;
Segment() {}
Segment(Point p1, Point p2) : p1(p1), p2(p2) {}
void get_cin() { cin >> p1.x >> p1.y >> p2.x >> p2.y; }
Point p1tp2() { return p2 - p1; }
Point p2tp1() { return p1 - p2; }
double abs() { return std::abs(norm()); }
double norm() { return (p2 - p1).norm(); }
};
bool Point::isOrthogonal(Segment s1, Segment s2) {
return EQ(dot(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}
bool Point::isPalallel(Segment s1, Segment s2) {
return EQ(cross(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}
bool Point::intersect(Segment s1, Segment s2) {
return intersect(s1.p1, s1.p2, s2.p1, s2.p2);
}
Point Point::project(Segment s, Point p) {
Point base = s.p2 - s.p1;
double r = Point::dot(p - s.p1, base) / base.norm();
return s.p1 + base * r;
}
Point Point::reflect(Segment s, Point p) { return (project(s, p) * 2) - p; }
double Point::getDistanceLP(Segment s, Point p) {
return std::abs(cross(s.p2 - s.p1, p - s.p1) / (s.p2 - s.p1).abs());
}
double Point::getDistanceSP(Segment s, Point p) {
if (dot(s.p2 - s.p1, p - s.p1) < 0.0)
return (p - s.p1).abs();
if (dot(s.p1 - s.p2, p - s.p2) < 0.0)
return (p - s.p2).abs();
return getDistanceLP(s, p);
}
double Point::getDistance(Segment s1, Segment s2) {
if (intersect(s1, s2))
return 0.0;
return min({getDistanceSP(s1, s2.p1), getDistanceSP(s1, s2.p2),
getDistanceSP(s2, s1.p1), getDistanceSP(s2, s1.p2)});
}
Point Point::getIntersection(Segment s1, Segment s2) {
// (s1.p1 - s2.p1).norm()
auto bs = s1.p2 - s1.p1;
auto n1 = s2.p1 - s1.p1;
auto n2 = s2.p2 - s1.p1;
auto c1 = std::abs(cross(n1, bs)) / bs.norm();
auto c2 = std::abs(cross(n2, bs)) / bs.norm();
return s2.p1 + (s2.p2 - s2.p1) * (c1 / (c1 + c2));
// c1:c2=t:1-t
// c2t=(1-t)c1
// t/(1-t)=c1/(c1+c2)
//
}
double arg(Point p) { return atan2(p.y, p.x); }
Point polar(double a, double r) { return Point(cos(r) * a, sin(r) * a); }
class Circle {
public:
Point c;
double r;
Circle(Point c = Point(), double r = 0.0) : c(c), r(r) {}
void get_cin() { cin >> c.x >> c.y >> r; }
static pair<Point, Point> getCrossPoints(Circle c1, Circle c2) {
double d = (c1.c - c2.c).abs(); // 中心点どうしの距離
double a = acos((c1.r * c1.r + d * d - c2.r * c2.r) / (2 * c1.r * d));
double t = arg(c2.c - c1.c);
return make_pair(c1.c + polar(c1.r, t + a), c1.c + polar(c1.r, t - a));
}
};
pair<Point, Point> Point::crossPoints(Circle c, Segment s) {
auto pp = project(s, c.c);
auto f = (pp - c.c).norm();
auto mu = sqrt(c.r * c.r - f);
auto e = s.p1tp2() / s.p1tp2().abs();
return make_pair(pp + e * mu, pp - e * mu);
}
ll divRm(string s, ll x) {
ll r = 0;
for (ll i = 0; i < s.size(); i++) {
r *= 10;
r += s[i] - '0';
r %= x;
}
return r;
}
ll cmbi(ll x, ll b) {
ll res = 1;
for (size_t i = 0; i < b; i++) {
res *= x - i;
res %= INF;
res *= inv[b - i];
res %= INF;
}
return res;
}
double digsum(ll x) {
ll res = 0;
while (x > 0) {
res += x % 10;
x /= 10;
}
return res;
}
bool check_parindrome(string s) {
int n = s.size();
rep(i, n / 2) {
if (s[i] != s[n - i - 1]) {
return false;
}
}
return true;
}
// ここまでライブラリ
// ここからコード
vector<vector<edge>> es;
ll col[100010], dis[100010];
ll ans[100010];
struct query {
ll c, d, i;
bool lca;
};
vector<query> Q[100010]; // 頂点に対してどのqueryがあるか
pll colr[100010];
void euler(ll x, ll f, ll d) {
for (auto v : Q[x]) {
ll val = d - colr[v.c].second + colr[v.c].first * v.d;
if (v.lca) {
ans[v.i] -= val * 2;
} else {
ans[v.i] += val;
}
}
for (auto v : es[x]) {
if (v.to == f)
continue;
int color = col[v.i];
colr[color].first++;
colr[color].second += dis[v.i];
euler(v.to, x, d + dis[v.i]);
colr[color].first--;
colr[color].second -= dis[v.i];
}
}
void solv() {
ll q;
cin >> n >> q;
es = vector<vector<edge>>(n + 1);
rep(i, n - 1) {
ll a, b;
cin >> a >> b >> col[i] >> dis[i];
es[a].push_back(edge(b, i));
es[b].push_back(edge(a, i));
}
LCA lca(n, 1, es);
rep(i, q) {
ll x, y, u, v;
cin >> x >> y >> u >> v;
Q[u].push_back({x, y, i, false});
Q[v].push_back({x, y, i, false});
Q[lca.lca(u, v)].push_back({x, y, i, true});
}
euler(1, 0, 0);
rep(i, q) { cout << ans[i] << endl; }
}
int main() {
COMinit();
solv();
return 0;
}
| [
"assignment.change"
] | 793,191 | 793,192 | u224756887 | cpp |
p02986 | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI pair<int, int>
const int maxm = 5e6 + 5;
struct EE {
int v, c, d;
};
struct QQ {
int x, y, op, id;
};
vector<EE> g[maxm];
vector<QQ> Q[maxm];
const int maxd = 20;
int f[maxm][25];
int d[maxm];
int ans[maxm];
int n, q;
void dfs1(int x, int fa) {
for (int j = 1; j <= maxd; j++) {
f[x][j] = f[f[x][j - 1]][j - 1];
}
for (auto i : g[x]) {
int v = i.v;
if (v == fa)
continue;
d[v] = d[x] + 1;
f[v][0] = x;
dfs1(v, x);
}
}
int lca(int a, int b) {
if (d[a] < d[b])
swap(a, b); //把a定为更深的
for (int i = maxd; i >= 0; i--) { //爬到同一高度
if (d[f[a][i]] >= d[b]) {
a = f[a][i];
}
}
if (a == b)
return a;
for (int i = maxd; i >= 0; i--) {
if (f[a][i] != f[b][i]) {
a = f[a][i];
b = f[b][i];
}
}
return f[a][0];
}
//
int sum[maxm];
int cnt[maxm];
//
void dfs(int x, int fa, int dist) {
for (auto i : Q[x]) {
int x = i.x, y = i.y;
ans[i.id] += i.op * (dist - sum[x] + cnt[x] * y);
}
for (auto i : g[x]) {
int v = i.v;
if (v == fa)
continue;
cnt[i.c]++;
sum[i.c] += i.d;
dfs(v, x, dist + i.d);
cnt[i.c]--;
sum[i.c] -= i.d;
}
}
signed main() {
ios::sync_with_stdio(0);
cin >> n >> q;
for (int i = 1; i < n; i++) {
int a, b, c, d;
cin >> a >> b >> c >> d;
g[a].push_back({b, c, d});
g[b].push_back({a, c, d});
}
dfs1(1, 1);
for (int i = 1; i <= q; i++) {
int x, y, u, v;
cin >> x >> y >> u >> v;
int lc = lca(u, v);
Q[u].push_back({x, y, 1, i});
Q[v].push_back({x, y, 1, i});
Q[lc].push_back({x, y, -1, i});
}
dfs(1, 1, 0);
for (int i = 1; i <= q; i++) {
cout << ans[i] << endl;
}
return 0;
}
/*
在线做法:
树上距离可以用lca做,
边权替换操作只需要计算u和v之间有多少个颜色为x的边以及其边权和,
是在树上建可持久化线段树,直接维护就行了,
(或者树剖转序列再建树)
离线做法:
将询问拆分为u,v,lca三个点的询问,
每个询问查询当前点到根的距离-颜色为x的边权和+cnt[x]*y
颜色为x的边权和、cnt[x]直接用数组就可以维护了,
最后答案就是ans[u]+ans[v]-ans[lca].
*/
| #include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI pair<int, int>
const int maxm = 1e5 + 5;
struct EE {
int v, c, d;
};
struct QQ {
int x, y, op, id;
};
vector<EE> g[maxm];
vector<QQ> Q[maxm];
const int maxd = 20;
int f[maxm][25];
int d[maxm];
int ans[maxm];
int n, q;
void dfs1(int x, int fa) {
for (int j = 1; j <= maxd; j++) {
f[x][j] = f[f[x][j - 1]][j - 1];
}
for (auto i : g[x]) {
int v = i.v;
if (v == fa)
continue;
d[v] = d[x] + 1;
f[v][0] = x;
dfs1(v, x);
}
}
int lca(int a, int b) {
if (d[a] < d[b])
swap(a, b);
for (int i = maxd; i >= 0; i--) {
if (d[f[a][i]] >= d[b]) {
a = f[a][i];
}
}
if (a == b)
return a;
for (int i = maxd; i >= 0; i--) {
if (f[a][i] != f[b][i]) {
a = f[a][i];
b = f[b][i];
}
}
return f[a][0];
}
//
int sum[maxm];
int cnt[maxm];
//
void dfs(int x, int fa, int dist) {
for (auto i : Q[x]) {
int x = i.x, y = i.y;
ans[i.id] += i.op * (dist - sum[x] + cnt[x] * y);
}
for (auto i : g[x]) {
int v = i.v;
if (v == fa)
continue;
cnt[i.c]++;
sum[i.c] += i.d;
dfs(v, x, dist + i.d);
cnt[i.c]--;
sum[i.c] -= i.d;
}
}
signed main() {
ios::sync_with_stdio(0);
cin >> n >> q;
for (int i = 1; i < n; i++) {
int a, b, c, d;
cin >> a >> b >> c >> d;
g[a].push_back({b, c, d});
g[b].push_back({a, c, d});
}
dfs1(1, 1);
for (int i = 1; i <= q; i++) {
int x, y, u, v;
cin >> x >> y >> u >> v;
int lc = lca(u, v);
Q[u].push_back({x, y, 1, i});
Q[v].push_back({x, y, 1, i});
Q[lc].push_back({x, y, -2, i});
}
dfs(1, 1, 0);
for (int i = 1; i <= q; i++) {
cout << ans[i] << endl;
}
return 0;
}
/*
在线做法:
树上距离可以用lca做,
边权替换操作只需要计算u和v之间有多少个颜色为x的边以及其边权和,
是在树上建可持久化线段树,直接维护就行了,
(或者树剖转序列再建树)
离线做法:
将询问拆分为u,v,lca三个点的询问,
每个询问查询当前点到根的距离-颜色为x的边权和+cnt[x]*y
颜色为x的边权和、cnt[x]直接用数组就可以维护了,
最后答案就是ans[u]+ans[v]-2*ans[lca].
*/
| [
"literal.number.change",
"expression.operation.binary.change",
"call.arguments.change"
] | 793,202 | 793,203 | u068827347 | cpp |
p02986 | // #pragma GCC optimize(2)
// #pragma G++ optimize(2)
// #pragma comment(linker,"/STACK:102400000,102400000")
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef float fl;
typedef long double ld;
typedef pair<int, int> pii;
#if (WIN32) || (WIN64) || (__WIN32) || (__WIN64) || (_WIN32) || (_WIN64) || \
(WINDOWS)
#define lld "%I64d"
#define llu "%I64u"
#else
#define lld "%lld"
#define llu "%llu"
#endif
#define ui(n) ((unsigned int)(n))
#define LL(n) ((long long)(n))
#define ull(n) ((unsigned long long)(n))
#define fl(n) ((float)(n))
#define ld(n) ((long double)(n))
#define char(n) ((char)(n))
#define Bool(n) ((bool)(n))
#define fixpoint(n) fixed << setprecision(n)
const int INF = 1061109567;
const int NINF = -1044266559;
const LL LINF = 4557430888798830399;
const ld eps = 1e-15;
#define MOD (1000000007)
#define PI (3.1415926535897932384626433832795028841971)
#define MP make_pair
#define MT make_tuple
#define All(a) (a).begin(), (a).end()
#define pall(a) (a).rbegin(), (a).rend()
#define Log(x, y) log(x) / log(y)
#define SZ(a) ((int)(a).size())
#define rep(i, n) for (int i = 0; i < ((int)(n)); i++)
#define rep1(i, n) for (int i = 1; i <= ((int)(n)); i++)
#define repd(i, n) for (int i = ((int)(n)) - 1; i >= 0; i--)
#define repd1(i, n) for (int i = ((int)(n)); i >= 1; i--)
#define repv(itr, v) \
for (__typeof((v).begin()) itr = (v).begin(); itr != (v).end(); itr++)
#define repV(i, v) for (auto i : v)
#define repE(i, v) for (auto &i : v)
#define MS(x, y) memset(x, y, sizeof(x))
#define MC(x) MS(x, 0)
#define MINF(x) MS(x, 63)
#define MCP(x, y) memcpy(x, y, sizeof(y))
#define UN(v) sort(All(v)), v.erase(unique(All(v)), v.end())
#define filein(x) freopen(x, "r", stdin)
#define fileout(x) freopen(x, "w", stdout)
#define fileio(x) \
freopen(x ".in", "r", stdin); \
freopen(x ".out", "w", stdout)
#define filein2(filename, name) ifstream name(filename, ios::in)
#define fileout2(filename, name) ofstream name(filename, ios::out)
#define fileio2(filename, name) fstream name(filename, ios::in | ios::out)
#define sqr(x) ((x) * (x))
#define Pause system("pause")
#define Cls system("cls")
#define fs first
#define sc second
#define SF scanf
#define PF printf
inline int Read() {
int x = 0, w = 0;
char ch = 0;
while (!isdigit(ch)) {
w |= ch == '-';
ch = getchar();
}
while (isdigit(ch))
x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
return w ? -x : x;
}
inline void Write(int x) {
if (x < 0)
putchar('-'), x = -x;
if (x > 9)
Write(x / 10);
putchar(x % 10 + '0');
}
inline LL powmod(LL a, LL b) {
LL res = 1;
a %= MOD;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1)
res = res * a % MOD;
a = a * a % MOD;
}
return res % MOD;
}
inline LL gcdll(LL a, LL b) { return b ? gcdll(b, a % b) : a; }
const int dx[] = {0, 1, 0, -1, 1, -1, -1, 1};
const int dy[] = {1, 0, -1, 0, -1, -1, 1, 1};
/*********************************************************BEGIN*********************************************************/
const int maxn = 100010;
struct edge {
int v, col, len;
edge(int _v, int _col, int _len) : v(_v), col(_col), len(_len) {}
};
struct modify {
int idx, typ, col, mul;
modify(int _idx, int _typ, int _col, int _mul)
: idx(_idx), typ(_typ), col(_col), mul(_mul) {}
};
int n, q, dep[maxn], par[maxn][20];
vector<edge> e[maxn];
vector<modify> m[maxn];
LL ans[maxn], cnt[maxn], sum[maxn];
inline void dfs1(int u, int f) {
dep[u] = dep[f] + 1;
par[u][0] = f;
for (int i = 1; i < 20; i++)
par[u][i] = par[par[u][i - 1]][i - 1];
repV(i, e[u]) {
int v = i.v;
if (v != f)
dfs1(v, u);
}
}
inline void dfs2(int u, int f, LL d) {
repV(i, m[u]) {
int idx = i.idx, typ = i.typ, col = i.col, mul = i.mul;
if (typ == 1) {
ans[idx] += d * mul;
} else if (typ == 2) {
ans[idx] += sum[col] * mul;
} else {
ans[idx] += cnt[col] * mul;
}
}
repV(i, e[u]) {
int v = i.v, col = i.col, len = i.len;
if (v == f)
continue;
sum[col] += len;
cnt[col]++;
dfs2(v, u, d + len);
sum[col] -= len;
cnt[col]--;
}
}
inline int lca(int u, int v) {
if (dep[u] < dep[v])
swap(u, v);
for (int i = 0; dep[u] > dep[v]; i++)
if ((dep[u] - dep[v]) & (1 << i))
u = par[u][i];
if (u == v)
return u;
for (int i = 19; i >= 0; i--)
if (par[u][i] != par[v][i])
u = par[u][i], v = par[v][i];
return par[u][0];
}
int main() {
SF("%d%d", &n, &q);
for (int i = 0; i < n - 1; i++) {
int u, v, col, len;
SF("%d%d%d%d", &u, &v, &col, &len);
e[u].push_back(edge(v, col, len));
e[v].push_back(edge(u, col, len));
}
dfs1(1, 0);
for (int i = 1; i <= q; i++) {
int c, l, u, v;
SF("%d%d%d%d", &c, &l, &u, &v);
int w = lca(u, v);
m[u].push_back(modify(i, 1, 0, 1));
m[u].push_back(modify(i, 2, c, -1));
m[u].push_back(modify(1, 3, c, l));
m[v].push_back(modify(i, 1, 0, 1));
m[v].push_back(modify(i, 2, c, -1));
m[v].push_back(modify(i, 3, c, l));
m[w].push_back(modify(i, 1, 0, -2));
m[w].push_back(modify(i, 2, c, 2));
m[w].push_back(modify(i, 3, c, -2 * l));
}
dfs2(1, 0, 0);
for (int i = 1; i <= q; i++)
PF("%lld\n", ans[i]);
return 0;
}
/**********************************************************END**********************************************************/ | // #pragma GCC optimize(2)
// #pragma G++ optimize(2)
// #pragma comment(linker,"/STACK:102400000,102400000")
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef float fl;
typedef long double ld;
typedef pair<int, int> pii;
#if (WIN32) || (WIN64) || (__WIN32) || (__WIN64) || (_WIN32) || (_WIN64) || \
(WINDOWS)
#define lld "%I64d"
#define llu "%I64u"
#else
#define lld "%lld"
#define llu "%llu"
#endif
#define ui(n) ((unsigned int)(n))
#define LL(n) ((long long)(n))
#define ull(n) ((unsigned long long)(n))
#define fl(n) ((float)(n))
#define ld(n) ((long double)(n))
#define char(n) ((char)(n))
#define Bool(n) ((bool)(n))
#define fixpoint(n) fixed << setprecision(n)
const int INF = 1061109567;
const int NINF = -1044266559;
const LL LINF = 4557430888798830399;
const ld eps = 1e-15;
#define MOD (1000000007)
#define PI (3.1415926535897932384626433832795028841971)
#define MP make_pair
#define MT make_tuple
#define All(a) (a).begin(), (a).end()
#define pall(a) (a).rbegin(), (a).rend()
#define Log(x, y) log(x) / log(y)
#define SZ(a) ((int)(a).size())
#define rep(i, n) for (int i = 0; i < ((int)(n)); i++)
#define rep1(i, n) for (int i = 1; i <= ((int)(n)); i++)
#define repd(i, n) for (int i = ((int)(n)) - 1; i >= 0; i--)
#define repd1(i, n) for (int i = ((int)(n)); i >= 1; i--)
#define repv(itr, v) \
for (__typeof((v).begin()) itr = (v).begin(); itr != (v).end(); itr++)
#define repV(i, v) for (auto i : v)
#define repE(i, v) for (auto &i : v)
#define MS(x, y) memset(x, y, sizeof(x))
#define MC(x) MS(x, 0)
#define MINF(x) MS(x, 63)
#define MCP(x, y) memcpy(x, y, sizeof(y))
#define UN(v) sort(All(v)), v.erase(unique(All(v)), v.end())
#define filein(x) freopen(x, "r", stdin)
#define fileout(x) freopen(x, "w", stdout)
#define fileio(x) \
freopen(x ".in", "r", stdin); \
freopen(x ".out", "w", stdout)
#define filein2(filename, name) ifstream name(filename, ios::in)
#define fileout2(filename, name) ofstream name(filename, ios::out)
#define fileio2(filename, name) fstream name(filename, ios::in | ios::out)
#define sqr(x) ((x) * (x))
#define Pause system("pause")
#define Cls system("cls")
#define fs first
#define sc second
#define SF scanf
#define PF printf
inline int Read() {
int x = 0, w = 0;
char ch = 0;
while (!isdigit(ch)) {
w |= ch == '-';
ch = getchar();
}
while (isdigit(ch))
x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
return w ? -x : x;
}
inline void Write(int x) {
if (x < 0)
putchar('-'), x = -x;
if (x > 9)
Write(x / 10);
putchar(x % 10 + '0');
}
inline LL powmod(LL a, LL b) {
LL res = 1;
a %= MOD;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1)
res = res * a % MOD;
a = a * a % MOD;
}
return res % MOD;
}
inline LL gcdll(LL a, LL b) { return b ? gcdll(b, a % b) : a; }
const int dx[] = {0, 1, 0, -1, 1, -1, -1, 1};
const int dy[] = {1, 0, -1, 0, -1, -1, 1, 1};
/*********************************************************BEGIN*********************************************************/
const int maxn = 100010;
struct edge {
int v, col, len;
edge(int _v, int _col, int _len) : v(_v), col(_col), len(_len) {}
};
struct modify {
int idx, typ, col, mul;
modify(int _idx, int _typ, int _col, int _mul)
: idx(_idx), typ(_typ), col(_col), mul(_mul) {}
};
int n, q, dep[maxn], par[maxn][20];
vector<edge> e[maxn];
vector<modify> m[maxn];
LL ans[maxn], cnt[maxn], sum[maxn];
inline void dfs1(int u, int f) {
dep[u] = dep[f] + 1;
par[u][0] = f;
for (int i = 1; i < 20; i++)
par[u][i] = par[par[u][i - 1]][i - 1];
repV(i, e[u]) {
int v = i.v;
if (v != f)
dfs1(v, u);
}
}
inline void dfs2(int u, int f, LL d) {
repV(i, m[u]) {
int idx = i.idx, typ = i.typ, col = i.col, mul = i.mul;
if (typ == 1) {
ans[idx] += d * mul;
} else if (typ == 2) {
ans[idx] += sum[col] * mul;
} else {
ans[idx] += cnt[col] * mul;
}
}
repV(i, e[u]) {
int v = i.v, col = i.col, len = i.len;
if (v == f)
continue;
sum[col] += len;
cnt[col]++;
dfs2(v, u, d + len);
sum[col] -= len;
cnt[col]--;
}
}
inline int lca(int u, int v) {
if (dep[u] < dep[v])
swap(u, v);
for (int i = 0; dep[u] > dep[v]; i++)
if ((dep[u] - dep[v]) & (1 << i))
u = par[u][i];
if (u == v)
return u;
for (int i = 19; i >= 0; i--)
if (par[u][i] != par[v][i])
u = par[u][i], v = par[v][i];
return par[u][0];
}
int main() {
SF("%d%d", &n, &q);
for (int i = 0; i < n - 1; i++) {
int u, v, col, len;
SF("%d%d%d%d", &u, &v, &col, &len);
e[u].push_back(edge(v, col, len));
e[v].push_back(edge(u, col, len));
}
dfs1(1, 0);
for (int i = 1; i <= q; i++) {
int c, l, u, v;
SF("%d%d%d%d", &c, &l, &u, &v);
int w = lca(u, v);
m[u].push_back(modify(i, 1, 0, 1));
m[u].push_back(modify(i, 2, c, -1));
m[u].push_back(modify(i, 3, c, l));
m[v].push_back(modify(i, 1, 0, 1));
m[v].push_back(modify(i, 2, c, -1));
m[v].push_back(modify(i, 3, c, l));
m[w].push_back(modify(i, 1, 0, -2));
m[w].push_back(modify(i, 2, c, 2));
m[w].push_back(modify(i, 3, c, -2 * l));
}
dfs2(1, 0, 0);
for (int i = 1; i <= q; i++)
PF("%lld\n", ans[i]);
return 0;
}
/**********************************************************END**********************************************************/ | [
"identifier.replace.add",
"literal.replace.remove",
"call.arguments.change"
] | 793,223 | 793,224 | u584568363 | cpp |
p02986 | // #pragma GCC optimize(2)
// #pragma G++ optimize(2)
// #pragma comment(linker,"/STACK:102400000,102400000")
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef float fl;
typedef long double ld;
typedef pair<int, int> pii;
#if (WIN32) || (WIN64) || (__WIN32) || (__WIN64) || (_WIN32) || (_WIN64) || \
(WINDOWS)
#define lld "%I64d"
#define llu "%I64u"
#else
#define lld "%lld"
#define llu "%llu"
#endif
#define ui(n) ((unsigned int)(n))
#define LL(n) ((long long)(n))
#define ull(n) ((unsigned long long)(n))
#define fl(n) ((float)(n))
#define ld(n) ((long double)(n))
#define char(n) ((char)(n))
#define Bool(n) ((bool)(n))
#define fixpoint(n) fixed << setprecision(n)
const int INF = 1061109567;
const int NINF = -1044266559;
const LL LINF = 4557430888798830399;
const ld eps = 1e-15;
#define MOD (1000000007)
#define PI (3.1415926535897932384626433832795028841971)
#define MP make_pair
#define MT make_tuple
#define All(a) (a).begin(), (a).end()
#define pall(a) (a).rbegin(), (a).rend()
#define Log(x, y) log(x) / log(y)
#define SZ(a) ((int)(a).size())
#define rep(i, n) for (int i = 0; i < ((int)(n)); i++)
#define rep1(i, n) for (int i = 1; i <= ((int)(n)); i++)
#define repd(i, n) for (int i = ((int)(n)) - 1; i >= 0; i--)
#define repd1(i, n) for (int i = ((int)(n)); i >= 1; i--)
#define repv(itr, v) \
for (__typeof((v).begin()) itr = (v).begin(); itr != (v).end(); itr++)
#define repV(i, v) for (auto i : v)
#define repE(i, v) for (auto &i : v)
#define MS(x, y) memset(x, y, sizeof(x))
#define MC(x) MS(x, 0)
#define MINF(x) MS(x, 63)
#define MCP(x, y) memcpy(x, y, sizeof(y))
#define UN(v) sort(All(v)), v.erase(unique(All(v)), v.end())
#define filein(x) freopen(x, "r", stdin)
#define fileout(x) freopen(x, "w", stdout)
#define fileio(x) \
freopen(x ".in", "r", stdin); \
freopen(x ".out", "w", stdout)
#define filein2(filename, name) ifstream name(filename, ios::in)
#define fileout2(filename, name) ofstream name(filename, ios::out)
#define fileio2(filename, name) fstream name(filename, ios::in | ios::out)
#define sqr(x) ((x) * (x))
#define Pause system("pause")
#define Cls system("cls")
#define fs first
#define sc second
#define SF scanf
#define PF printf
inline int Read() {
int x = 0, w = 0;
char ch = 0;
while (!isdigit(ch)) {
w |= ch == '-';
ch = getchar();
}
while (isdigit(ch))
x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
return w ? -x : x;
}
inline void Write(int x) {
if (x < 0)
putchar('-'), x = -x;
if (x > 9)
Write(x / 10);
putchar(x % 10 + '0');
}
inline LL powmod(LL a, LL b) {
LL res = 1;
a %= MOD;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1)
res = res * a % MOD;
a = a * a % MOD;
}
return res % MOD;
}
inline LL gcdll(LL a, LL b) { return b ? gcdll(b, a % b) : a; }
const int dx[] = {0, 1, 0, -1, 1, -1, -1, 1};
const int dy[] = {1, 0, -1, 0, -1, -1, 1, 1};
/*********************************************************BEGIN*********************************************************/
const int maxn = 100010;
struct edge {
int v, col, len;
edge(int _v, int _col, int _len) : v(_v), col(_col), len(_len) {}
};
struct modify {
int idx, typ, col, mul;
modify(int _idx, int _typ, int _col, int _mul)
: idx(_idx), typ(_typ), col(_col), mul(_mul) {}
};
int n, q, dep[maxn], par[maxn][20];
vector<edge> e[maxn];
vector<modify> m[maxn];
LL ans[maxn], cnt[maxn], sum[maxn];
inline void dfs1(int u, int f) {
dep[u] = dep[f] + 1;
par[u][0] = f;
for (int i = 1; i < 20; i++)
par[u][i] = par[par[u][i - 1]][i - 1];
repV(i, e[u]) {
int v = i.v;
if (v != f)
dfs1(v, u);
}
}
inline void dfs2(int u, int f, LL d) {
repV(i, m[u]) {
int idx = i.idx, typ = i.typ, col = i.col, mul = i.mul;
if (typ == 1) {
ans[idx] += d * mul;
} else if (typ == 2) {
ans[idx] += sum[col] * mul;
} else {
ans[idx] += cnt[col] * mul;
}
}
repV(i, e[u]) {
int v = i.v, col = i.col, len = i.len;
if (v == f)
continue;
sum[col] += len;
cnt[col]++;
dfs2(v, u, d + len);
sum[col] -= len;
cnt[col]--;
}
}
inline int lca(int u, int v) {
if (dep[u] < dep[v])
swap(u, v);
for (int i = 0; dep[u] > dep[v]; i++)
if ((dep[u] - dep[v]) & (1 << i))
u = par[u][i];
if (u == v)
return u;
for (int i = 19; i >= 0; i--)
if (par[u][i] != par[v][i])
u = par[u][i], v = par[v][i];
return par[u][0];
}
int main() {
SF("%d%d", &n, &q);
for (int i = 0; i < n - 1; i++) {
int u, v, col, len;
SF("%d%d%d%d", &u, &v, &col, &len);
e[u].push_back(edge(v, col, len));
e[v].push_back(edge(u, col, len));
}
dfs1(1, 0);
for (int i = 1; i <= q; i++) {
int c, l, u, v;
SF("%d%d%d%d", &c, &l, &u, &v);
int w = lca(u, v);
m[u].push_back(modify(i, 1, 0, 1));
m[u].push_back(modify(i, 2, c, -1));
m[u].push_back(modify(1, 3, c, l));
m[v].push_back(modify(i, 1, 0, 1));
m[v].push_back(modify(i, 2, c, -1));
m[v].push_back(modify(i, 3, c, l));
m[w].push_back(modify(i, 1, 0, 2));
m[w].push_back(modify(i, 2, c, -2));
m[w].push_back(modify(i, 3, c, -2 * l));
}
dfs2(1, 0, 0);
for (int i = 1; i <= q; i++)
PF("%lld\n", ans[i]);
return 0;
}
/**********************************************************END**********************************************************/ | // #pragma GCC optimize(2)
// #pragma G++ optimize(2)
// #pragma comment(linker,"/STACK:102400000,102400000")
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef float fl;
typedef long double ld;
typedef pair<int, int> pii;
#if (WIN32) || (WIN64) || (__WIN32) || (__WIN64) || (_WIN32) || (_WIN64) || \
(WINDOWS)
#define lld "%I64d"
#define llu "%I64u"
#else
#define lld "%lld"
#define llu "%llu"
#endif
#define ui(n) ((unsigned int)(n))
#define LL(n) ((long long)(n))
#define ull(n) ((unsigned long long)(n))
#define fl(n) ((float)(n))
#define ld(n) ((long double)(n))
#define char(n) ((char)(n))
#define Bool(n) ((bool)(n))
#define fixpoint(n) fixed << setprecision(n)
const int INF = 1061109567;
const int NINF = -1044266559;
const LL LINF = 4557430888798830399;
const ld eps = 1e-15;
#define MOD (1000000007)
#define PI (3.1415926535897932384626433832795028841971)
#define MP make_pair
#define MT make_tuple
#define All(a) (a).begin(), (a).end()
#define pall(a) (a).rbegin(), (a).rend()
#define Log(x, y) log(x) / log(y)
#define SZ(a) ((int)(a).size())
#define rep(i, n) for (int i = 0; i < ((int)(n)); i++)
#define rep1(i, n) for (int i = 1; i <= ((int)(n)); i++)
#define repd(i, n) for (int i = ((int)(n)) - 1; i >= 0; i--)
#define repd1(i, n) for (int i = ((int)(n)); i >= 1; i--)
#define repv(itr, v) \
for (__typeof((v).begin()) itr = (v).begin(); itr != (v).end(); itr++)
#define repV(i, v) for (auto i : v)
#define repE(i, v) for (auto &i : v)
#define MS(x, y) memset(x, y, sizeof(x))
#define MC(x) MS(x, 0)
#define MINF(x) MS(x, 63)
#define MCP(x, y) memcpy(x, y, sizeof(y))
#define UN(v) sort(All(v)), v.erase(unique(All(v)), v.end())
#define filein(x) freopen(x, "r", stdin)
#define fileout(x) freopen(x, "w", stdout)
#define fileio(x) \
freopen(x ".in", "r", stdin); \
freopen(x ".out", "w", stdout)
#define filein2(filename, name) ifstream name(filename, ios::in)
#define fileout2(filename, name) ofstream name(filename, ios::out)
#define fileio2(filename, name) fstream name(filename, ios::in | ios::out)
#define sqr(x) ((x) * (x))
#define Pause system("pause")
#define Cls system("cls")
#define fs first
#define sc second
#define SF scanf
#define PF printf
inline int Read() {
int x = 0, w = 0;
char ch = 0;
while (!isdigit(ch)) {
w |= ch == '-';
ch = getchar();
}
while (isdigit(ch))
x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
return w ? -x : x;
}
inline void Write(int x) {
if (x < 0)
putchar('-'), x = -x;
if (x > 9)
Write(x / 10);
putchar(x % 10 + '0');
}
inline LL powmod(LL a, LL b) {
LL res = 1;
a %= MOD;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1)
res = res * a % MOD;
a = a * a % MOD;
}
return res % MOD;
}
inline LL gcdll(LL a, LL b) { return b ? gcdll(b, a % b) : a; }
const int dx[] = {0, 1, 0, -1, 1, -1, -1, 1};
const int dy[] = {1, 0, -1, 0, -1, -1, 1, 1};
/*********************************************************BEGIN*********************************************************/
const int maxn = 100010;
struct edge {
int v, col, len;
edge(int _v, int _col, int _len) : v(_v), col(_col), len(_len) {}
};
struct modify {
int idx, typ, col, mul;
modify(int _idx, int _typ, int _col, int _mul)
: idx(_idx), typ(_typ), col(_col), mul(_mul) {}
};
int n, q, dep[maxn], par[maxn][20];
vector<edge> e[maxn];
vector<modify> m[maxn];
LL ans[maxn], cnt[maxn], sum[maxn];
inline void dfs1(int u, int f) {
dep[u] = dep[f] + 1;
par[u][0] = f;
for (int i = 1; i < 20; i++)
par[u][i] = par[par[u][i - 1]][i - 1];
repV(i, e[u]) {
int v = i.v;
if (v != f)
dfs1(v, u);
}
}
inline void dfs2(int u, int f, LL d) {
repV(i, m[u]) {
int idx = i.idx, typ = i.typ, col = i.col, mul = i.mul;
if (typ == 1) {
ans[idx] += d * mul;
} else if (typ == 2) {
ans[idx] += sum[col] * mul;
} else {
ans[idx] += cnt[col] * mul;
}
}
repV(i, e[u]) {
int v = i.v, col = i.col, len = i.len;
if (v == f)
continue;
sum[col] += len;
cnt[col]++;
dfs2(v, u, d + len);
sum[col] -= len;
cnt[col]--;
}
}
inline int lca(int u, int v) {
if (dep[u] < dep[v])
swap(u, v);
for (int i = 0; dep[u] > dep[v]; i++)
if ((dep[u] - dep[v]) & (1 << i))
u = par[u][i];
if (u == v)
return u;
for (int i = 19; i >= 0; i--)
if (par[u][i] != par[v][i])
u = par[u][i], v = par[v][i];
return par[u][0];
}
int main() {
SF("%d%d", &n, &q);
for (int i = 0; i < n - 1; i++) {
int u, v, col, len;
SF("%d%d%d%d", &u, &v, &col, &len);
e[u].push_back(edge(v, col, len));
e[v].push_back(edge(u, col, len));
}
dfs1(1, 0);
for (int i = 1; i <= q; i++) {
int c, l, u, v;
SF("%d%d%d%d", &c, &l, &u, &v);
int w = lca(u, v);
m[u].push_back(modify(i, 1, 0, 1));
m[u].push_back(modify(i, 2, c, -1));
m[u].push_back(modify(i, 3, c, l));
m[v].push_back(modify(i, 1, 0, 1));
m[v].push_back(modify(i, 2, c, -1));
m[v].push_back(modify(i, 3, c, l));
m[w].push_back(modify(i, 1, 0, -2));
m[w].push_back(modify(i, 2, c, 2));
m[w].push_back(modify(i, 3, c, -2 * l));
}
dfs2(1, 0, 0);
for (int i = 1; i <= q; i++)
PF("%lld\n", ans[i]);
return 0;
}
/**********************************************************END**********************************************************/ | [
"identifier.replace.add",
"literal.replace.remove",
"call.arguments.change",
"expression.operation.unary.arithmetic.add",
"expression.operation.unary.arithmetic.remove"
] | 793,225 | 793,224 | u584568363 | cpp |
p02986 | // #pragma GCC optimize(2)
// #pragma G++ optimize(2)
// #pragma comment(linker,"/STACK:102400000,102400000")
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef float fl;
typedef long double ld;
typedef pair<int, int> pii;
#if (WIN32) || (WIN64) || (__WIN32) || (__WIN64) || (_WIN32) || (_WIN64) || \
(WINDOWS)
#define lld "%I64d"
#define llu "%I64u"
#else
#define lld "%lld"
#define llu "%llu"
#endif
#define ui(n) ((unsigned int)(n))
#define LL(n) ((long long)(n))
#define ull(n) ((unsigned long long)(n))
#define fl(n) ((float)(n))
#define ld(n) ((long double)(n))
#define char(n) ((char)(n))
#define Bool(n) ((bool)(n))
#define fixpoint(n) fixed << setprecision(n)
const int INF = 1061109567;
const int NINF = -1044266559;
const LL LINF = 4557430888798830399;
const ld eps = 1e-15;
#define MOD (1000000007)
#define PI (3.1415926535897932384626433832795028841971)
#define MP make_pair
#define MT make_tuple
#define All(a) (a).begin(), (a).end()
#define pall(a) (a).rbegin(), (a).rend()
#define Log(x, y) log(x) / log(y)
#define SZ(a) ((int)(a).size())
#define rep(i, n) for (int i = 0; i < ((int)(n)); i++)
#define rep1(i, n) for (int i = 1; i <= ((int)(n)); i++)
#define repd(i, n) for (int i = ((int)(n)) - 1; i >= 0; i--)
#define repd1(i, n) for (int i = ((int)(n)); i >= 1; i--)
#define repv(itr, v) \
for (__typeof((v).begin()) itr = (v).begin(); itr != (v).end(); itr++)
#define repV(i, v) for (auto i : v)
#define repE(i, v) for (auto &i : v)
#define MS(x, y) memset(x, y, sizeof(x))
#define MC(x) MS(x, 0)
#define MINF(x) MS(x, 63)
#define MCP(x, y) memcpy(x, y, sizeof(y))
#define UN(v) sort(All(v)), v.erase(unique(All(v)), v.end())
#define filein(x) freopen(x, "r", stdin)
#define fileout(x) freopen(x, "w", stdout)
#define fileio(x) \
freopen(x ".in", "r", stdin); \
freopen(x ".out", "w", stdout)
#define filein2(filename, name) ifstream name(filename, ios::in)
#define fileout2(filename, name) ofstream name(filename, ios::out)
#define fileio2(filename, name) fstream name(filename, ios::in | ios::out)
#define sqr(x) ((x) * (x))
#define Pause system("pause")
#define Cls system("cls")
#define fs first
#define sc second
#define SF scanf
#define PF printf
inline int Read() {
int x = 0, w = 0;
char ch = 0;
while (!isdigit(ch)) {
w |= ch == '-';
ch = getchar();
}
while (isdigit(ch))
x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
return w ? -x : x;
}
inline void Write(int x) {
if (x < 0)
putchar('-'), x = -x;
if (x > 9)
Write(x / 10);
putchar(x % 10 + '0');
}
inline LL powmod(LL a, LL b) {
LL res = 1;
a %= MOD;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1)
res = res * a % MOD;
a = a * a % MOD;
}
return res % MOD;
}
inline LL gcdll(LL a, LL b) { return b ? gcdll(b, a % b) : a; }
const int dx[] = {0, 1, 0, -1, 1, -1, -1, 1};
const int dy[] = {1, 0, -1, 0, -1, -1, 1, 1};
/*********************************************************BEGIN*********************************************************/
const int maxn = 100010;
struct edge {
int v, col, len;
edge(int _v, int _col, int _len) : v(_v), col(_col), len(_len) {}
};
struct modify {
int idx, typ, col, mul;
modify(int _idx, int _typ, int _col, int _mul)
: idx(_idx), typ(_typ), col(_col), mul(_mul) {}
};
int n, q, dep[maxn], par[maxn][20];
vector<edge> e[maxn];
vector<modify> m[maxn];
LL ans[maxn], cnt[maxn], sum[maxn];
inline void dfs1(int u, int f) {
dep[u] = dep[f] + 1;
par[u][0] = f;
for (int i = 1; i < 20; i++)
par[u][i] = par[par[u][i - 1]][i - 1];
repV(i, e[u]) {
int v = i.v;
if (v != f)
dfs1(v, u);
}
}
inline void dfs2(int u, int f, LL d) {
repV(i, m[u]) {
int idx = i.idx, typ = i.typ, col = i.col, mul = i.mul;
if (typ == 1) {
ans[idx] += d * mul;
} else if (typ == 2) {
ans[idx] += sum[col] * mul;
} else {
ans[idx] += cnt[col] * mul;
}
}
repV(i, e[u]) {
int v = i.v, col = i.col, len = i.len;
if (v == f)
continue;
sum[col] += len;
cnt[col]++;
dfs2(v, u, d + len);
sum[col] -= len;
cnt[col]--;
}
}
inline int lca(int u, int v) {
if (dep[u] < dep[v])
swap(u, v);
for (int i = 0; dep[u] > dep[v]; i++)
if ((dep[u] - dep[v]) & (1 << i))
u = par[u][i];
if (u == v)
return u;
for (int i = 19; i >= 0; i--)
if (par[u][i] != par[v][i])
u = par[u][i], v = par[v][i];
return par[u][0];
}
int main() {
SF("%d%d", &n, &q);
for (int i = 0; i < n - 1; i++) {
int u, v, col, len;
SF("%d%d%d%d", &u, &v, &col, &len);
e[u].push_back(edge(v, col, len));
e[v].push_back(edge(u, col, len));
}
dfs1(1, 0);
for (int i = 1; i <= q; i++) {
int c, l, u, v;
SF("%d%d%d%d", &c, &l, &u, &v);
int w = lca(u, v);
m[u].push_back(modify(i, 1, 0, 1));
m[u].push_back(modify(i, 2, c, -1));
m[u].push_back(modify(1, 3, c, l));
m[v].push_back(modify(i, 1, 0, 1));
m[v].push_back(modify(i, 2, c, -1));
m[v].push_back(modify(i, 3, c, l));
m[w].push_back(modify(i, 1, 0, 2));
m[w].push_back(modify(i, 2, c, -2));
m[w].push_back(modify(1, 3, c, -2 * l));
}
dfs2(1, 0, 0);
for (int i = 1; i <= q; i++)
PF("%lld\n", ans[i]);
return 0;
}
/**********************************************************END**********************************************************/ | // #pragma GCC optimize(2)
// #pragma G++ optimize(2)
// #pragma comment(linker,"/STACK:102400000,102400000")
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef float fl;
typedef long double ld;
typedef pair<int, int> pii;
#if (WIN32) || (WIN64) || (__WIN32) || (__WIN64) || (_WIN32) || (_WIN64) || \
(WINDOWS)
#define lld "%I64d"
#define llu "%I64u"
#else
#define lld "%lld"
#define llu "%llu"
#endif
#define ui(n) ((unsigned int)(n))
#define LL(n) ((long long)(n))
#define ull(n) ((unsigned long long)(n))
#define fl(n) ((float)(n))
#define ld(n) ((long double)(n))
#define char(n) ((char)(n))
#define Bool(n) ((bool)(n))
#define fixpoint(n) fixed << setprecision(n)
const int INF = 1061109567;
const int NINF = -1044266559;
const LL LINF = 4557430888798830399;
const ld eps = 1e-15;
#define MOD (1000000007)
#define PI (3.1415926535897932384626433832795028841971)
#define MP make_pair
#define MT make_tuple
#define All(a) (a).begin(), (a).end()
#define pall(a) (a).rbegin(), (a).rend()
#define Log(x, y) log(x) / log(y)
#define SZ(a) ((int)(a).size())
#define rep(i, n) for (int i = 0; i < ((int)(n)); i++)
#define rep1(i, n) for (int i = 1; i <= ((int)(n)); i++)
#define repd(i, n) for (int i = ((int)(n)) - 1; i >= 0; i--)
#define repd1(i, n) for (int i = ((int)(n)); i >= 1; i--)
#define repv(itr, v) \
for (__typeof((v).begin()) itr = (v).begin(); itr != (v).end(); itr++)
#define repV(i, v) for (auto i : v)
#define repE(i, v) for (auto &i : v)
#define MS(x, y) memset(x, y, sizeof(x))
#define MC(x) MS(x, 0)
#define MINF(x) MS(x, 63)
#define MCP(x, y) memcpy(x, y, sizeof(y))
#define UN(v) sort(All(v)), v.erase(unique(All(v)), v.end())
#define filein(x) freopen(x, "r", stdin)
#define fileout(x) freopen(x, "w", stdout)
#define fileio(x) \
freopen(x ".in", "r", stdin); \
freopen(x ".out", "w", stdout)
#define filein2(filename, name) ifstream name(filename, ios::in)
#define fileout2(filename, name) ofstream name(filename, ios::out)
#define fileio2(filename, name) fstream name(filename, ios::in | ios::out)
#define sqr(x) ((x) * (x))
#define Pause system("pause")
#define Cls system("cls")
#define fs first
#define sc second
#define SF scanf
#define PF printf
inline int Read() {
int x = 0, w = 0;
char ch = 0;
while (!isdigit(ch)) {
w |= ch == '-';
ch = getchar();
}
while (isdigit(ch))
x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
return w ? -x : x;
}
inline void Write(int x) {
if (x < 0)
putchar('-'), x = -x;
if (x > 9)
Write(x / 10);
putchar(x % 10 + '0');
}
inline LL powmod(LL a, LL b) {
LL res = 1;
a %= MOD;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1)
res = res * a % MOD;
a = a * a % MOD;
}
return res % MOD;
}
inline LL gcdll(LL a, LL b) { return b ? gcdll(b, a % b) : a; }
const int dx[] = {0, 1, 0, -1, 1, -1, -1, 1};
const int dy[] = {1, 0, -1, 0, -1, -1, 1, 1};
/*********************************************************BEGIN*********************************************************/
const int maxn = 100010;
struct edge {
int v, col, len;
edge(int _v, int _col, int _len) : v(_v), col(_col), len(_len) {}
};
struct modify {
int idx, typ, col, mul;
modify(int _idx, int _typ, int _col, int _mul)
: idx(_idx), typ(_typ), col(_col), mul(_mul) {}
};
int n, q, dep[maxn], par[maxn][20];
vector<edge> e[maxn];
vector<modify> m[maxn];
LL ans[maxn], cnt[maxn], sum[maxn];
inline void dfs1(int u, int f) {
dep[u] = dep[f] + 1;
par[u][0] = f;
for (int i = 1; i < 20; i++)
par[u][i] = par[par[u][i - 1]][i - 1];
repV(i, e[u]) {
int v = i.v;
if (v != f)
dfs1(v, u);
}
}
inline void dfs2(int u, int f, LL d) {
repV(i, m[u]) {
int idx = i.idx, typ = i.typ, col = i.col, mul = i.mul;
if (typ == 1) {
ans[idx] += d * mul;
} else if (typ == 2) {
ans[idx] += sum[col] * mul;
} else {
ans[idx] += cnt[col] * mul;
}
}
repV(i, e[u]) {
int v = i.v, col = i.col, len = i.len;
if (v == f)
continue;
sum[col] += len;
cnt[col]++;
dfs2(v, u, d + len);
sum[col] -= len;
cnt[col]--;
}
}
inline int lca(int u, int v) {
if (dep[u] < dep[v])
swap(u, v);
for (int i = 0; dep[u] > dep[v]; i++)
if ((dep[u] - dep[v]) & (1 << i))
u = par[u][i];
if (u == v)
return u;
for (int i = 19; i >= 0; i--)
if (par[u][i] != par[v][i])
u = par[u][i], v = par[v][i];
return par[u][0];
}
int main() {
SF("%d%d", &n, &q);
for (int i = 0; i < n - 1; i++) {
int u, v, col, len;
SF("%d%d%d%d", &u, &v, &col, &len);
e[u].push_back(edge(v, col, len));
e[v].push_back(edge(u, col, len));
}
dfs1(1, 0);
for (int i = 1; i <= q; i++) {
int c, l, u, v;
SF("%d%d%d%d", &c, &l, &u, &v);
int w = lca(u, v);
m[u].push_back(modify(i, 1, 0, 1));
m[u].push_back(modify(i, 2, c, -1));
m[u].push_back(modify(i, 3, c, l));
m[v].push_back(modify(i, 1, 0, 1));
m[v].push_back(modify(i, 2, c, -1));
m[v].push_back(modify(i, 3, c, l));
m[w].push_back(modify(i, 1, 0, -2));
m[w].push_back(modify(i, 2, c, 2));
m[w].push_back(modify(i, 3, c, -2 * l));
}
dfs2(1, 0, 0);
for (int i = 1; i <= q; i++)
PF("%lld\n", ans[i]);
return 0;
}
/**********************************************************END**********************************************************/ | [
"identifier.replace.add",
"literal.replace.remove",
"call.arguments.change",
"expression.operation.unary.arithmetic.add",
"expression.operation.unary.arithmetic.remove"
] | 793,226 | 793,224 | u584568363 | cpp |
p02986 | // #pragma GCC optimize(2)
// #pragma G++ optimize(2)
// #pragma comment(linker,"/STACK:102400000,102400000")
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef float fl;
typedef long double ld;
typedef pair<int, int> pii;
#if (WIN32) || (WIN64) || (__WIN32) || (__WIN64) || (_WIN32) || (_WIN64) || \
(WINDOWS)
#define lld "%I64d"
#define llu "%I64u"
#else
#define lld "%lld"
#define llu "%llu"
#endif
#define ui(n) ((unsigned int)(n))
#define LL(n) ((long long)(n))
#define ull(n) ((unsigned long long)(n))
#define fl(n) ((float)(n))
#define ld(n) ((long double)(n))
#define char(n) ((char)(n))
#define Bool(n) ((bool)(n))
#define fixpoint(n) fixed << setprecision(n)
const int INF = 1061109567;
const int NINF = -1044266559;
const LL LINF = 4557430888798830399;
const ld eps = 1e-15;
#define MOD (1000000007)
#define PI (3.1415926535897932384626433832795028841971)
#define MP make_pair
#define MT make_tuple
#define All(a) (a).begin(), (a).end()
#define pall(a) (a).rbegin(), (a).rend()
#define Log(x, y) log(x) / log(y)
#define SZ(a) ((int)(a).size())
#define rep(i, n) for (int i = 0; i < ((int)(n)); i++)
#define rep1(i, n) for (int i = 1; i <= ((int)(n)); i++)
#define repd(i, n) for (int i = ((int)(n)) - 1; i >= 0; i--)
#define repd1(i, n) for (int i = ((int)(n)); i >= 1; i--)
#define repv(itr, v) \
for (__typeof((v).begin()) itr = (v).begin(); itr != (v).end(); itr++)
#define repV(i, v) for (auto i : v)
#define repE(i, v) for (auto &i : v)
#define MS(x, y) memset(x, y, sizeof(x))
#define MC(x) MS(x, 0)
#define MINF(x) MS(x, 63)
#define MCP(x, y) memcpy(x, y, sizeof(y))
#define UN(v) sort(All(v)), v.erase(unique(All(v)), v.end())
#define filein(x) freopen(x, "r", stdin)
#define fileout(x) freopen(x, "w", stdout)
#define fileio(x) \
freopen(x ".in", "r", stdin); \
freopen(x ".out", "w", stdout)
#define filein2(filename, name) ifstream name(filename, ios::in)
#define fileout2(filename, name) ofstream name(filename, ios::out)
#define fileio2(filename, name) fstream name(filename, ios::in | ios::out)
#define sqr(x) ((x) * (x))
#define Pause system("pause")
#define Cls system("cls")
#define fs first
#define sc second
#define SF scanf
#define PF printf
inline int Read() {
int x = 0, w = 0;
char ch = 0;
while (!isdigit(ch)) {
w |= ch == '-';
ch = getchar();
}
while (isdigit(ch))
x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
return w ? -x : x;
}
inline void Write(int x) {
if (x < 0)
putchar('-'), x = -x;
if (x > 9)
Write(x / 10);
putchar(x % 10 + '0');
}
inline LL powmod(LL a, LL b) {
LL res = 1;
a %= MOD;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1)
res = res * a % MOD;
a = a * a % MOD;
}
return res % MOD;
}
inline LL gcdll(LL a, LL b) { return b ? gcdll(b, a % b) : a; }
const int dx[] = {0, 1, 0, -1, 1, -1, -1, 1};
const int dy[] = {1, 0, -1, 0, -1, -1, 1, 1};
/*********************************************************BEGIN*********************************************************/
const int maxn = 100010;
struct edge {
int v, col, len;
edge(int _v, int _col, int _len) : v(_v), col(_col), len(_len) {}
};
struct modify {
int idx, typ, col, mul;
modify(int _idx, int _typ, int _col, int _mul)
: idx(_idx), typ(_typ), col(_col), mul(_mul) {}
};
int n, q, dep[maxn], par[maxn][20];
vector<edge> e[maxn];
vector<modify> m[maxn];
LL ans[maxn], cnt[maxn], sum[maxn];
inline void dfs1(int u, int f) {
dep[u] = dep[f] + 1;
par[u][0] = f;
for (int i = 1; i < 20; i++)
par[u][i] = par[par[u][i - 1]][i - 1];
repV(i, e[u]) {
int v = i.v;
if (v != f)
dfs1(v, u);
}
}
inline void dfs2(int u, int f, LL d) {
repV(i, m[u]) {
int idx = i.idx, typ = i.typ, col = i.col, mul = i.mul;
if (typ == 1) {
ans[idx] += d * mul;
} else if (typ == 2) {
ans[idx] += sum[col] * mul;
} else {
ans[idx] += cnt[col] * mul;
}
}
repV(i, e[u]) {
int v = i.v, col = i.col, len = i.len;
if (v == f)
continue;
sum[col] += len;
cnt[col]++;
dfs2(v, u, d + len);
sum[col] -= len;
cnt[col]--;
}
}
inline int lca(int u, int v) {
if (dep[u] < dep[v])
swap(u, v);
for (int i = 0; dep[u] > dep[v]; i++)
if ((dep[u] - dep[v]) & (1 << i))
u = par[u][i];
if (u == v)
return u;
for (int i = 19; i >= 0; i--)
if (par[u][i] != par[v][i])
u = par[u][i], v = par[v][i];
return par[u][0];
}
int main() {
SF("%d%d", &n, &q);
for (int i = 0; i < n - 1; i++) {
int u, v, col, len;
SF("%d%d%d%d", &u, &v, &col, &len);
e[u].push_back(edge(v, col, len));
e[v].push_back(edge(u, col, len));
}
dfs1(1, 0);
for (int i = 1; i <= q; i++) {
int c, l, u, v;
SF("%d%d%d%d", &c, &l, &u, &v);
int w = lca(u, v);
m[u].push_back(modify(i, 1, 0, 1));
m[u].push_back(modify(i, 2, c, -1));
m[u].push_back(modify(1, 3, c, l));
m[v].push_back(modify(i, 1, 0, 1));
m[v].push_back(modify(i, 2, c, -1));
m[v].push_back(modify(i, 3, c, l));
m[w].push_back(modify(i, 1, 0, 2));
m[w].push_back(modify(i, 2, c, -2));
m[w].push_back(modify(1, 3, c, -2 * l));
}
dfs2(1, 0, 0);
for (int i = 1; i <= q; i++)
PF("%d\n", ans[i]);
return 0;
}
/**********************************************************END**********************************************************/ | // #pragma GCC optimize(2)
// #pragma G++ optimize(2)
// #pragma comment(linker,"/STACK:102400000,102400000")
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef float fl;
typedef long double ld;
typedef pair<int, int> pii;
#if (WIN32) || (WIN64) || (__WIN32) || (__WIN64) || (_WIN32) || (_WIN64) || \
(WINDOWS)
#define lld "%I64d"
#define llu "%I64u"
#else
#define lld "%lld"
#define llu "%llu"
#endif
#define ui(n) ((unsigned int)(n))
#define LL(n) ((long long)(n))
#define ull(n) ((unsigned long long)(n))
#define fl(n) ((float)(n))
#define ld(n) ((long double)(n))
#define char(n) ((char)(n))
#define Bool(n) ((bool)(n))
#define fixpoint(n) fixed << setprecision(n)
const int INF = 1061109567;
const int NINF = -1044266559;
const LL LINF = 4557430888798830399;
const ld eps = 1e-15;
#define MOD (1000000007)
#define PI (3.1415926535897932384626433832795028841971)
#define MP make_pair
#define MT make_tuple
#define All(a) (a).begin(), (a).end()
#define pall(a) (a).rbegin(), (a).rend()
#define Log(x, y) log(x) / log(y)
#define SZ(a) ((int)(a).size())
#define rep(i, n) for (int i = 0; i < ((int)(n)); i++)
#define rep1(i, n) for (int i = 1; i <= ((int)(n)); i++)
#define repd(i, n) for (int i = ((int)(n)) - 1; i >= 0; i--)
#define repd1(i, n) for (int i = ((int)(n)); i >= 1; i--)
#define repv(itr, v) \
for (__typeof((v).begin()) itr = (v).begin(); itr != (v).end(); itr++)
#define repV(i, v) for (auto i : v)
#define repE(i, v) for (auto &i : v)
#define MS(x, y) memset(x, y, sizeof(x))
#define MC(x) MS(x, 0)
#define MINF(x) MS(x, 63)
#define MCP(x, y) memcpy(x, y, sizeof(y))
#define UN(v) sort(All(v)), v.erase(unique(All(v)), v.end())
#define filein(x) freopen(x, "r", stdin)
#define fileout(x) freopen(x, "w", stdout)
#define fileio(x) \
freopen(x ".in", "r", stdin); \
freopen(x ".out", "w", stdout)
#define filein2(filename, name) ifstream name(filename, ios::in)
#define fileout2(filename, name) ofstream name(filename, ios::out)
#define fileio2(filename, name) fstream name(filename, ios::in | ios::out)
#define sqr(x) ((x) * (x))
#define Pause system("pause")
#define Cls system("cls")
#define fs first
#define sc second
#define SF scanf
#define PF printf
inline int Read() {
int x = 0, w = 0;
char ch = 0;
while (!isdigit(ch)) {
w |= ch == '-';
ch = getchar();
}
while (isdigit(ch))
x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
return w ? -x : x;
}
inline void Write(int x) {
if (x < 0)
putchar('-'), x = -x;
if (x > 9)
Write(x / 10);
putchar(x % 10 + '0');
}
inline LL powmod(LL a, LL b) {
LL res = 1;
a %= MOD;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1)
res = res * a % MOD;
a = a * a % MOD;
}
return res % MOD;
}
inline LL gcdll(LL a, LL b) { return b ? gcdll(b, a % b) : a; }
const int dx[] = {0, 1, 0, -1, 1, -1, -1, 1};
const int dy[] = {1, 0, -1, 0, -1, -1, 1, 1};
/*********************************************************BEGIN*********************************************************/
const int maxn = 100010;
struct edge {
int v, col, len;
edge(int _v, int _col, int _len) : v(_v), col(_col), len(_len) {}
};
struct modify {
int idx, typ, col, mul;
modify(int _idx, int _typ, int _col, int _mul)
: idx(_idx), typ(_typ), col(_col), mul(_mul) {}
};
int n, q, dep[maxn], par[maxn][20];
vector<edge> e[maxn];
vector<modify> m[maxn];
LL ans[maxn], cnt[maxn], sum[maxn];
inline void dfs1(int u, int f) {
dep[u] = dep[f] + 1;
par[u][0] = f;
for (int i = 1; i < 20; i++)
par[u][i] = par[par[u][i - 1]][i - 1];
repV(i, e[u]) {
int v = i.v;
if (v != f)
dfs1(v, u);
}
}
inline void dfs2(int u, int f, LL d) {
repV(i, m[u]) {
int idx = i.idx, typ = i.typ, col = i.col, mul = i.mul;
if (typ == 1) {
ans[idx] += d * mul;
} else if (typ == 2) {
ans[idx] += sum[col] * mul;
} else {
ans[idx] += cnt[col] * mul;
}
}
repV(i, e[u]) {
int v = i.v, col = i.col, len = i.len;
if (v == f)
continue;
sum[col] += len;
cnt[col]++;
dfs2(v, u, d + len);
sum[col] -= len;
cnt[col]--;
}
}
inline int lca(int u, int v) {
if (dep[u] < dep[v])
swap(u, v);
for (int i = 0; dep[u] > dep[v]; i++)
if ((dep[u] - dep[v]) & (1 << i))
u = par[u][i];
if (u == v)
return u;
for (int i = 19; i >= 0; i--)
if (par[u][i] != par[v][i])
u = par[u][i], v = par[v][i];
return par[u][0];
}
int main() {
SF("%d%d", &n, &q);
for (int i = 0; i < n - 1; i++) {
int u, v, col, len;
SF("%d%d%d%d", &u, &v, &col, &len);
e[u].push_back(edge(v, col, len));
e[v].push_back(edge(u, col, len));
}
dfs1(1, 0);
for (int i = 1; i <= q; i++) {
int c, l, u, v;
SF("%d%d%d%d", &c, &l, &u, &v);
int w = lca(u, v);
m[u].push_back(modify(i, 1, 0, 1));
m[u].push_back(modify(i, 2, c, -1));
m[u].push_back(modify(i, 3, c, l));
m[v].push_back(modify(i, 1, 0, 1));
m[v].push_back(modify(i, 2, c, -1));
m[v].push_back(modify(i, 3, c, l));
m[w].push_back(modify(i, 1, 0, -2));
m[w].push_back(modify(i, 2, c, 2));
m[w].push_back(modify(i, 3, c, -2 * l));
}
dfs2(1, 0, 0);
for (int i = 1; i <= q; i++)
PF("%lld\n", ans[i]);
return 0;
}
/**********************************************************END**********************************************************/ | [
"identifier.replace.add",
"literal.replace.remove",
"call.arguments.change",
"expression.operation.unary.arithmetic.add",
"expression.operation.unary.arithmetic.remove",
"literal.string.change"
] | 793,227 | 793,224 | u584568363 | cpp |
p02936 | #include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef pair<ll, ll> Pair;
#define mp(x, y) make_pair(x, y)
typedef queue<int> qi;
typedef queue<string> qs;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = (a); i <= (b); i++)
#define repm(i, n) for (int i = n; i >= 0; i--)
#define all(v) v.begin(), v.end()
// sort( all(v) ) などと使える
// nが素数かをO(√n)で判断
bool is_prime(int n) {
bool res = true;
if (n == 1)
return false;
else if (n == 2)
return true;
else {
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) {
res = false;
break;
}
}
}
return res;
}
int perm(int n, int r) {
if (r == 1)
return n;
return n * perm(n - 1, r - 1);
}
int fact(int n) {
if (n == 1)
return 1;
return fact(n - 1) * n;
}
int comb(int n, int r) {
int a = min(n, r), b = max(n, r);
return perm(a, b) / fact(a);
}
/*
ll pow_mod(ll a, ll n, ll mod) {
ll res = 1;
ll base = a;
while (n) {
if (n & 1) res = res * base % mod;
base = base * base % mod;
n >>= 1;
}
return res;
}
*/
// aの逆元 (a^(-1))を求める
ll inv_mod(ll a, ll mod) {
ll b = mod, u = 1, v = 0;
while (b) {
ll t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= mod;
if (u < 0)
u += mod;
return u;
}
/*
ll fact_mod(ll n, ll mod) {
if (n == 1) return 1;
return n * fact_mod(n - 1, mod) * mod;
}
*/
// 階乗 (mod とりバージョン)
ll fact_mod(ll n, ll mod) {
ll f = 1;
for (int i = 2; i <= n; i++)
f = f * (i % mod) % mod;
return f;
}
ll pow_mod(ll x, ll n, ll mod) {
ll res = 1;
while (n > 0) {
if (n & 1)
res = (res * x) % mod; //ビット演算(最下位ビットが1のとき)
x = (x * x) % mod;
n >>= 1; //右シフト(n = n >> 1)
}
return res;
}
// 組み合わせ nCr を求める (modあり)
ll comb_mod(ll n, ll r, ll mod) {
if (r > n - r)
r = n - r;
if (r == 0)
return 1;
ll a = 1;
for (int i = 0; i < r; i++)
a = a * ((n - i) % mod) % mod;
ll b = pow_mod(fact_mod(r, mod), mod - 2, mod);
return (a % mod) * (b % mod) % mod;
}
int N, Q;
vvi G;
vll c;
vector<bool> seen;
void dfs(int v) {
seen[v] = true;
for (auto nv : G[v]) {
if (seen[nv])
continue;
else {
c[nv] += c[v];
dfs(nv);
}
}
}
int main() {
cin >> N >> Q;
G.resize(N);
c.resize(N, 0);
seen.assign(N, false);
rep(i, N) {
int a, b;
cin >> a >> b;
a--, b--;
G[a].push_back(b);
G[b].push_back(a);
}
rep(i, Q) {
int x;
ll p;
cin >> x >> p;
x--;
c[x] += p;
}
// DFS
dfs(0);
// output
rep(i, N) cout << c[i] << " ";
} | #include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef pair<ll, ll> Pair;
#define mp(x, y) make_pair(x, y)
typedef queue<int> qi;
typedef queue<string> qs;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = (a); i <= (b); i++)
#define repm(i, n) for (int i = n; i >= 0; i--)
#define all(v) v.begin(), v.end()
// sort( all(v) ) などと使える
// nが素数かをO(√n)で判断
bool is_prime(int n) {
bool res = true;
if (n == 1)
return false;
else if (n == 2)
return true;
else {
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) {
res = false;
break;
}
}
}
return res;
}
int perm(int n, int r) {
if (r == 1)
return n;
return n * perm(n - 1, r - 1);
}
int fact(int n) {
if (n == 1)
return 1;
return fact(n - 1) * n;
}
int comb(int n, int r) {
int a = min(n, r), b = max(n, r);
return perm(a, b) / fact(a);
}
/*
ll pow_mod(ll a, ll n, ll mod) {
ll res = 1;
ll base = a;
while (n) {
if (n & 1) res = res * base % mod;
base = base * base % mod;
n >>= 1;
}
return res;
}
*/
// aの逆元 (a^(-1))を求める
ll inv_mod(ll a, ll mod) {
ll b = mod, u = 1, v = 0;
while (b) {
ll t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= mod;
if (u < 0)
u += mod;
return u;
}
/*
ll fact_mod(ll n, ll mod) {
if (n == 1) return 1;
return n * fact_mod(n - 1, mod) * mod;
}
*/
// 階乗 (mod とりバージョン)
ll fact_mod(ll n, ll mod) {
ll f = 1;
for (int i = 2; i <= n; i++)
f = f * (i % mod) % mod;
return f;
}
ll pow_mod(ll x, ll n, ll mod) {
ll res = 1;
while (n > 0) {
if (n & 1)
res = (res * x) % mod; //ビット演算(最下位ビットが1のとき)
x = (x * x) % mod;
n >>= 1; //右シフト(n = n >> 1)
}
return res;
}
// 組み合わせ nCr を求める (modあり)
ll comb_mod(ll n, ll r, ll mod) {
if (r > n - r)
r = n - r;
if (r == 0)
return 1;
ll a = 1;
for (int i = 0; i < r; i++)
a = a * ((n - i) % mod) % mod;
ll b = pow_mod(fact_mod(r, mod), mod - 2, mod);
return (a % mod) * (b % mod) % mod;
}
int N, Q;
vvi G;
vll c;
vector<bool> seen;
void dfs(int v) {
seen[v] = true;
for (auto nv : G[v]) {
if (seen[nv])
continue;
else {
c[nv] += c[v];
dfs(nv);
}
}
}
int main() {
cin >> N >> Q;
G.resize(N);
c.resize(N, 0);
seen.assign(N, false);
rep(i, N - 1) {
int a, b;
cin >> a >> b;
a--, b--;
G[a].push_back(b);
G[b].push_back(a);
}
rep(i, Q) {
int x;
ll p;
cin >> x >> p;
x--;
c[x] += p;
}
// DFS
dfs(0);
// output
rep(i, N) cout << c[i] << " ";
} | [
"expression.operation.binary.add"
] | 793,241 | 793,242 | u400107908 | cpp |
p02936 | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
vector<vector<int>> v(1000000);
vector<int> ans(1000000, 0);
void rec(int i, int j = -1) {
for (int k : v[i]) {
if (k == j)
continue;
ans[k] += ans[i];
rec(k, j);
}
}
void solve() {
int n, q;
cin >> n >> q;
v.resize(n);
rep(i, n - 1) {
int a, b;
cin >> a >> b;
a--, b--;
v[a].push_back(b);
v[b].push_back(a);
}
ans.resize(n);
rep(i, q) {
int p, x;
cin >> p >> x;
p--;
ans[p] += x;
}
rec(0);
rep(i, n) cout << ans[i] << " ";
}
int main() {
solve();
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
vector<vector<int>> v(1000000);
vector<int> ans(1000000, 0);
void rec(int i, int j = -1) {
for (int k : v[i]) {
if (k == j)
continue;
ans[k] += ans[i];
rec(k, i);
}
}
void solve() {
int n, q;
cin >> n >> q;
v.resize(n);
rep(i, n - 1) {
int a, b;
cin >> a >> b;
a--, b--;
v[a].push_back(b);
v[b].push_back(a);
}
ans.resize(n);
rep(i, q) {
int p, x;
cin >> p >> x;
p--;
ans[p] += x;
}
rec(0);
rep(i, n) cout << ans[i] << " ";
}
int main() {
solve();
return 0;
} | [
"identifier.change",
"call.arguments.change"
] | 793,258 | 793,259 | u280175105 | cpp |
p02936 | #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset> // bitset
#include <deque> // deque
#include <iomanip> // setprecision
#include <iostream> // cout, endl, cin
#include <map> // map
#include <math.h> // sqrt
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <string> // string, to_string, stoi
#include <tuple> // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility> // pair, make_pair
#include <vector> // vector
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<long long>;
using pii = pair<int, int>;
using psi = pair<string, int>;
void f(vector<vi> &data, vi &num, vll &ans, ll sum, int n) {
sum += ll(num[n]);
ans[n - 1] = sum;
for (int x : data[n]) {
if (ans[x - 1] != 0) {
continue;
}
f(data, num, ans, sum, x);
}
}
int main() {
int N, Q;
cin >> N >> Q;
vector<vi> data(N + 1);
for (int i = 0; i < N - 1; i++) {
int a, b;
cin >> a >> b;
data[a].push_back(b);
data[b].push_back(a);
}
vi num(N + 1, 0);
for (int i = 0; i < Q; i++) {
int p, x;
cin >> p >> x;
num[p] += x;
}
vll ans(N, 0);
f(data, num, ans, 0, 1);
for (int i = 0; i < N; i++) {
cout << ans[i] << " ";
}
cout << endl;
}
| #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset> // bitset
#include <deque> // deque
#include <iomanip> // setprecision
#include <iostream> // cout, endl, cin
#include <map> // map
#include <math.h> // sqrt
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <string> // string, to_string, stoi
#include <tuple> // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility> // pair, make_pair
#include <vector> // vector
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<long long>;
using pii = pair<int, int>;
using psi = pair<string, int>;
void f(vector<vi> &data, vi &num, vll &ans, ll sum, int n) {
sum += ll(num[n]);
ans[n - 1] = sum;
for (int x : data[n]) {
if (ans[x - 1] != -1) {
continue;
}
f(data, num, ans, sum, x);
}
}
int main() {
int N, Q;
cin >> N >> Q;
vector<vi> data(N + 1);
for (int i = 0; i < N - 1; i++) {
int a, b;
cin >> a >> b;
data[a].push_back(b);
data[b].push_back(a);
}
vi num(N + 1, 0);
for (int i = 0; i < Q; i++) {
int p, x;
cin >> p >> x;
num[p] += x;
}
vll ans(N, -1);
f(data, num, ans, 0, 1);
for (int i = 0; i < N; i++) {
cout << ans[i] << " ";
}
cout << endl;
}
| [
"literal.number.change",
"control_flow.branch.if.condition.change",
"call.arguments.change"
] | 793,288 | 793,289 | u204514518 | cpp |
p02936 | #include <bits/stdc++.h>
using namespace std;
#define f(i, a, b) for (int i = a; i < b; i++)
#define pb push_back
using vi = vector<int>;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
int q;
cin >> q;
vi adj[n];
f(i, 0, n - 1) {
int a, b;
cin >> a >> b;
adj[--a].pb(--b);
adj[b].pb(a);
}
vi ans(n, 0);
function<void(int, int)> dfs = [&](int v, int p) {
if (p == -1)
ans[v] += ans[p];
for (int w : adj[v])
if (w != p)
dfs(w, v);
};
f(_, 0, q) {
int p, x;
cin >> p >> x;
ans[--p] += x;
}
dfs(0, -1);
f(i, 0, n) cout << ans[i] << " ";
cout << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define f(i, a, b) for (int i = a; i < b; i++)
#define pb push_back
using vi = vector<int>;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
int q;
cin >> q;
vi adj[n];
f(i, 0, n - 1) {
int a, b;
cin >> a >> b;
adj[--a].pb(--b);
adj[b].pb(a);
}
vi ans(n, 0);
function<void(int, int)> dfs = [&](int v, int p) {
if (p != -1)
ans[v] += ans[p];
for (int w : adj[v])
if (w != p)
dfs(w, v);
};
f(_, 0, q) {
int p, x;
cin >> p >> x;
ans[--p] += x;
}
dfs(0, -1);
f(i, 0, n) cout << ans[i] << " ";
cout << endl;
return 0;
} | [
"misc.opposites",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 793,292 | 793,293 | u018679195 | cpp |
p02936 | #include <bits/stdc++.h>
using namespace ::std;
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef array<int, 3> tri;
typedef long double ld;
template <class T> istream &operator>>(istream &I, vector<T> &v) {
for (T &e : v)
I >> e;
return I;
}
template <class T> ostream &operator<<(ostream &O, const vector<T> &v) {
for (const T &e : v)
O << e << ' ';
return O;
}
const int N = 2e5 + 7;
vector<int> adj[N];
vector<int> sts;
vector<int> where;
int here;
void dfs(int a, int p) {
where[a] = ++here;
sts[a] = 1;
for (auto b : adj[a]) {
if (p ^ b) {
dfs(b, a);
sts[a] += sts[b];
}
}
}
void _main() {
int n, q;
cin >> n >> q;
sts.resize(n + 2), where.resize(n + 2);
for (int i = 1; i <= n - 1; i++) {
int a, b;
cin >> a >> b;
adj[a].emplace_back(b);
adj[b].emplace_back(a);
}
dfs(1, 0);
vector<int> ans(n + 1);
while (q--) {
int a, b;
cin >> a >> b;
ans[where[a]] += b;
ans[where[a] + sts[a]]--;
}
for (int i = 1; i <= n + 1; i++)
ans[i] += ans[i - 1];
for (int i = 1; i <= n; i++)
cout << ans[where[i]] << ' ';
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("input.txt", "r", stdin);
int _t = 1;
// cin >> _t;
while (_t--)
_main();
return 0;
} | #include <bits/stdc++.h>
using namespace ::std;
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef array<int, 3> tri;
typedef long double ld;
template <class T> istream &operator>>(istream &I, vector<T> &v) {
for (T &e : v)
I >> e;
return I;
}
template <class T> ostream &operator<<(ostream &O, const vector<T> &v) {
for (const T &e : v)
O << e << ' ';
return O;
}
const int N = 2e5 + 7;
vector<int> adj[N];
vector<int> sts;
vector<int> where;
int here;
void dfs(int a, int p) {
where[a] = ++here;
sts[a] = 1;
for (auto b : adj[a]) {
if (p ^ b) {
dfs(b, a);
sts[a] += sts[b];
}
}
}
void _main() {
int n, q;
cin >> n >> q;
sts.resize(n + 2), where.resize(n + 2);
for (int i = 1; i <= n - 1; i++) {
int a, b;
cin >> a >> b;
adj[a].emplace_back(b);
adj[b].emplace_back(a);
}
dfs(1, 0);
vector<ll> ans(n + 1);
while (q--) {
int a, b;
cin >> a >> b;
ans[where[a]] += b;
ans[where[a] + sts[a]] -= b;
}
for (int i = 1; i <= n + 1; i++)
ans[i] += ans[i - 1];
for (int i = 1; i <= n; i++)
cout << ans[where[i]] << ' ';
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("input.txt", "r", stdin);
int _t = 1;
// cin >> _t;
while (_t--)
_main();
return 0;
} | [] | 793,302 | 793,303 | u093681822 | cpp |
p02936 | #include <bits/stdc++.h>
using namespace std;
//----------------------------MACROS-------------------------------------------------
#define pb \
insert // |
#define eb \
emplace_back // |
#define ff \
first // |
#define ss \
second // |
typedef long long int
ll; // |
typedef long double
ld; // |
#define all(a) \
a.begin(), a.end() // |
#define show(x) \
cerr << #x << " is " << x << "\n" // |
#define show2(x, y) \
cerr << #x << " " << #y << " " << x << " " << y << "\n" // |
typedef vector<ll>
vl; // |
typedef vector<vl>
vvl; // |
typedef pair<ll, ll>
pp; // |
typedef vector<pp>
vp; // |
typedef map<pp, ll>
ipi; // |
typedef map<pp, char>
ipc; // |
typedef map<ll, ll>
ii; // |
typedef set<ll>
sl; // |
typedef multiset<ll>
msl; // |
typedef map<char, ll>
ci; // |
typedef set<pair<ll, ll>>
sp; // |
const ll mod =
1e9 + 7; // |
const ll N =
2e5 + 1; // |
//----------------------------------------------------------------------------------
vl grp[N];
vl ans(N, 0);
vl val(N, 0);
vl vis(N, 0);
void dfs(ll x, ll adds) {
ans[x] = adds + val[x - 1];
for (auto i : grp[x]) {
if (!vis[i]) {
vis[i] = 1;
dfs(i, ans[x]);
}
}
}
void solve() {
ll n, q;
cin >> n >> q;
for (int i = 0; i < n - 1; i++) {
ll x, y;
cin >> x >> y;
grp[x].eb(y);
grp[y].eb(x);
}
while (q--) {
ll a, b;
cin >> a >> b;
val[a - 1] = b;
}
vis[1] = 1;
dfs(1, 0);
for (int i = 1; i <= n; i++)
cout << ans[i] << " ";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll t;
t = 1;
// cin>>t;
while (t--)
solve();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
// krishrawat
//----------------------------MACROS-------------------------------------------------
#define pb \
insert // |
#define eb \
emplace_back // |
#define ff \
first // |
#define ss \
second // |
typedef long long int
ll; // |
typedef long double
ld; // |
#define all(a) \
a.begin(), a.end() // |
#define show(x) \
cerr << #x << " is " << x << "\n" // |
#define show2(x, y) \
cerr << #x << " " << #y << " " << x << " " << y << "\n" // |
typedef vector<ll>
vl; // |
typedef vector<vl>
vvl; // |
typedef pair<ll, ll>
pp; // |
typedef vector<pp>
vp; // |
typedef map<pp, ll>
ipi; // |
typedef map<pp, char>
ipc; // |
typedef map<ll, ll>
ii; // |
typedef set<ll>
sl; // |
typedef multiset<ll>
msl; // |
typedef map<char, ll>
ci; // |
typedef set<pair<ll, ll>>
sp; // |
const ll mod =
1e9 + 7; // |
const ll N =
2e5 + 1; // |
//----------------------------------------------------------------------------------
vl grp[N];
vl ans(N, 0);
vl val(N, 0);
vl vis(N, 0);
void dfs(ll x, ll adds) {
ans[x] = adds + val[x - 1];
for (auto i : grp[x]) {
if (!vis[i]) {
vis[i] = 1;
dfs(i, ans[x]);
}
}
}
void solve() {
ll n, q;
cin >> n >> q;
for (int i = 0; i < n - 1; i++) {
ll x, y;
cin >> x >> y;
grp[x].eb(y);
grp[y].eb(x);
}
while (q--) {
ll a, b;
cin >> a >> b;
val[a - 1] += b;
}
vis[1] = 1;
dfs(1, 0);
for (int i = 1; i <= n; i++)
cout << ans[i] << " ";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll t;
t = 1;
// cin>>t;
while (t--)
solve();
return 0;
} | [
"assignment.value.change"
] | 793,322 | 793,323 | u706984643 | cpp |
p02936 | #include <bits/stdc++.h>
using namespace std;
// krishrawat
//----------------------------MACROS-------------------------------------------------
#define pb \
insert // |
#define eb \
emplace_back // |
#define ff \
first // |
#define ss \
second // |
typedef long long int
ll; // |
typedef long double
ld; // |
#define all(a) \
a.begin(), a.end() // |
#define show(x) \
cerr << #x << " is " << x << "\n" // |
#define show2(x, y) \
cerr << #x << " " << #y << " " << x << " " << y << "\n" // |
typedef vector<ll>
vl; // |
typedef vector<vl>
vvl; // |
typedef pair<ll, ll>
pp; // |
typedef vector<pp>
vp; // |
typedef map<pp, ll>
ipi; // |
typedef map<pp, char>
ipc; // |
typedef map<ll, ll>
ii; // |
typedef set<ll>
sl; // |
typedef multiset<ll>
msl; // |
typedef map<char, ll>
ci; // |
typedef set<pair<ll, ll>>
sp; // |
const ll mod =
1e9 + 7; // |
const ll N =
1e5 + 1; // |
//----------------------------------------------------------------------------------
vl grp[N];
vl ans(N, 0);
vl val(N, 0);
vl vis(N, 0);
void dfs(ll x, ll adds) {
ans[x] = adds + val[x - 1];
for (auto i : grp[x]) {
if (!vis[i]) {
vis[i] = 1;
dfs(i, ans[x]);
}
}
}
void solve() {
ll n, q;
cin >> n >> q;
for (int i = 0; i < n - 1; i++) {
ll x, y;
cin >> x >> y;
grp[x].eb(y);
grp[y].eb(x);
}
while (q--) {
ll a, b;
cin >> a >> b;
val[a - 1] = b;
}
vis[1] = 1;
dfs(1, 0);
for (int i = 1; i <= n; i++)
cout << ans[i] << " ";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll t;
t = 1;
// cin>>t;
while (t--)
solve();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
// krishrawat
//----------------------------MACROS-------------------------------------------------
#define pb \
insert // |
#define eb \
emplace_back // |
#define ff \
first // |
#define ss \
second // |
typedef long long int
ll; // |
typedef long double
ld; // |
#define all(a) \
a.begin(), a.end() // |
#define show(x) \
cerr << #x << " is " << x << "\n" // |
#define show2(x, y) \
cerr << #x << " " << #y << " " << x << " " << y << "\n" // |
typedef vector<ll>
vl; // |
typedef vector<vl>
vvl; // |
typedef pair<ll, ll>
pp; // |
typedef vector<pp>
vp; // |
typedef map<pp, ll>
ipi; // |
typedef map<pp, char>
ipc; // |
typedef map<ll, ll>
ii; // |
typedef set<ll>
sl; // |
typedef multiset<ll>
msl; // |
typedef map<char, ll>
ci; // |
typedef set<pair<ll, ll>>
sp; // |
const ll mod =
1e9 + 7; // |
const ll N =
2e5 + 1; // |
//----------------------------------------------------------------------------------
vl grp[N];
vl ans(N, 0);
vl val(N, 0);
vl vis(N, 0);
void dfs(ll x, ll adds) {
ans[x] = adds + val[x - 1];
for (auto i : grp[x]) {
if (!vis[i]) {
vis[i] = 1;
dfs(i, ans[x]);
}
}
}
void solve() {
ll n, q;
cin >> n >> q;
for (int i = 0; i < n - 1; i++) {
ll x, y;
cin >> x >> y;
grp[x].eb(y);
grp[y].eb(x);
}
while (q--) {
ll a, b;
cin >> a >> b;
val[a - 1] += b;
}
vis[1] = 1;
dfs(1, 0);
for (int i = 1; i <= n; i++)
cout << ans[i] << " ";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll t;
t = 1;
// cin>>t;
while (t--)
solve();
return 0;
} | [
"literal.number.change",
"expression.operation.binary.change",
"assignment.value.change"
] | 793,324 | 793,323 | u706984643 | cpp |
p02984 | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define st(arr, a) memset(arr, a, sizeof arr)
#define nl cout << endl
#define real signed
#define endl '\n'
#define bitcount(x) __builtin_popcountll(x)
const int MOD = 1000000007ll;
#define forn(i, a, b) for (int i = a; i <= b; i++)
#define rfor(i, a, b) for (int i = a; i >= b; i--)
#define all(x) x.begin(), x.end()
#define pi pair<int, int>
#define X first
#define Y second
#define N 1014159
#define vi vector<int>
#define v vector
signed solve() {
int n;
cin >> n;
int arr[n + 10];
int sum = 0;
forn(i, 1, n) {
cin >> arr[i];
if (i % 2)
sum += 2 * (arr[i]);
else
sum -= 2 * arr[i];
}
int ans[n + 10];
// cout<<sum;
ans[1] = sum / 2;
forn(i, 2, n) { ans[i] = 2 * arr[i] - ans[i - 1]; }
forn(i, 1, n) cout << ans[i] << " ";
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t = 1;
// cin>>t;
while (t--) {
solve();
}
return 0;
}
// g++ -g c.cpp ; ./a.exe | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define st(arr, a) memset(arr, a, sizeof arr)
#define nl cout << endl
#define real signed
#define endl '\n'
#define bitcount(x) __builtin_popcountll(x)
const int MOD = 1000000007ll;
#define forn(i, a, b) for (int i = a; i <= b; i++)
#define rfor(i, a, b) for (int i = a; i >= b; i--)
#define all(x) x.begin(), x.end()
#define pi pair<int, int>
#define X first
#define Y second
#define N 1014159
#define vi vector<int>
#define v vector
signed solve() {
int n;
cin >> n;
int arr[n + 10];
int sum = 0;
forn(i, 1, n) {
cin >> arr[i];
if (i % 2)
sum += 2 * (arr[i]);
else
sum -= 2 * arr[i];
}
int ans[n + 10];
// cout<<sum;
ans[1] = sum / 2;
forn(i, 2, n) { ans[i] = 2 * arr[i - 1] - ans[i - 1]; }
forn(i, 1, n) cout << ans[i] << " ";
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t = 1;
// cin>>t;
while (t--) {
solve();
}
return 0;
}
// g++ -g c.cpp ; ./a.exe | [
"assignment.change"
] | 793,338 | 793,339 | u691533014 | cpp |
p02984 | #include <iostream>
using namespace std;
int n;
int main() {
int a1 = 0, pm = 1;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
a[i] *= 2;
a1 += a[i] * pm;
pm *= -1;
}
a1 /= 2;
int prev = a1;
cout << a1 << " ";
for (int i = 0; i < n - 1; i++) {
cout << a[i] - prev;
if (i != n - 2)
cout << " ";
prev = a[i] - prev;
}
} | #include <iostream>
using namespace std;
int n;
int main() {
long a1 = 0, pm = 1;
cin >> n;
long a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
a[i] *= 2;
a1 += a[i] * pm;
pm *= -1;
}
a1 /= 2;
long prev = a1;
cout << a1 << " ";
for (int i = 0; i < n - 1; i++) {
cout << a[i] - prev;
if (i != n - 2)
cout << " ";
prev = a[i] - prev;
}
} | [
"variable_declaration.type.primitive.change"
] | 793,340 | 793,341 | u683313061 | cpp |
p02984 | #include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
if (fopen("input.in", "r")) {
freopen("input.in", "r", stdin);
freopen("output.out", "w", stdout);
}
int n;
cin >> n;
int a[100000];
for (int i = 0; i < n; i++)
cin >> a[i];
int constant = a[0] * 2;
for (int i = 1; i < n; i++) {
constant = a[i] * 2 - constant;
}
int ans[100000];
ans[0] = constant / 2;
for (int i = 1; i < n; i++) {
ans[i] = a[i - 1] * 2 - ans[i - 1];
}
for (int i = 0; i < n; i++)
cout << ans[i] << " ";
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
if (fopen("input.in", "r")) {
freopen("input.in", "r", stdin);
freopen("output.out", "w", stdout);
}
int n;
cin >> n;
long long a[100000];
for (int i = 0; i < n; i++)
cin >> a[i];
long long constant = a[0] * 2;
for (int i = 1; i < n; i++) {
constant = a[i] * 2 - constant;
}
long long ans[100000];
ans[0] = constant / 2;
for (int i = 1; i < n; i++) {
ans[i] = a[i - 1] * 2 - ans[i - 1];
}
for (int i = 0; i < n; i++)
cout << ans[i] << " ";
}
| [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 793,342 | 793,343 | u505762531 | cpp |
p02984 | #include <algorithm>
#include <cmath>
#include <cstdio>
using namespace std;
#define MAXN 100005
#define MOD 2019
#define LL long long
int n;
int a[MAXN], x[MAXN];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
if (i % 2)
x[1] += 2 * a[i];
else
x[1] -= 2 * a[i];
}
x[1] /= 2;
for (int i = 2; i <= n; i++)
x[i] = 2 * a[i - 1] - x[i - 1];
for (int i = 1; i < n; i++)
printf("%d ", x[i]);
printf("%d\n", x[n]);
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
using namespace std;
#define MAXN 100005
#define MOD 2019
#define LL long long
int n;
LL a[MAXN], x[MAXN];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%lld", &a[i]);
if (i % 2)
x[1] += 2 * a[i];
else
x[1] -= 2 * a[i];
}
x[1] /= 2;
for (int i = 2; i <= n; i++)
x[i] = 2 * a[i - 1] - x[i - 1];
for (int i = 1; i < n; i++)
printf("%lld ", x[i]);
printf("%lld\n", x[n]);
return 0;
}
// LL不开毁前程 | [
"variable_declaration.type.change",
"literal.string.change",
"call.arguments.change",
"io.output.change"
] | 793,368 | 793,369 | u158378528 | cpp |
p02984 | #include <algorithm>
#include <cmath>
#include <cstdio>
using namespace std;
#define MAXN 100005
#define MOD 2019
#define LL long long
int n;
int a[MAXN], x[MAXN];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
if (i % 2)
x[1] += 2 * a[i];
else
x[1] -= 2 * a[i];
}
x[1] /= 2;
for (int i = 2; i <= n; i++)
x[i] = 2 * a[i - 1] - x[i - 1];
for (int i = 1; i < n; i++)
printf("%d ", x[i]);
printf("%d\n", x[n]);
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
using namespace std;
#define MAXN 100005
#define MOD 2019
#define LL long long
int n;
LL a[MAXN], x[MAXN];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%lld", &a[i]);
if (i % 2)
x[1] += 2 * a[i];
else
x[1] -= 2 * a[i];
}
x[1] /= 2;
for (int i = 2; i <= n; i++)
x[i] = 2 * a[i - 1] - x[i - 1];
for (int i = 1; i < n; i++)
printf("%lld ", x[i]);
printf("%lld\n", x[n]);
return 0;
} | [
"variable_declaration.type.change",
"literal.string.change",
"call.arguments.change",
"io.output.change"
] | 793,368 | 793,370 | u158378528 | cpp |
p02984 | #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0, i##_l = (n); i < i##_l; i++)
int main() {
int N;
cin >> N;
vector<int> A(N);
int d = 0, d2 = 0;
REP(i, N) {
cin >> A[i];
d += A[i] * pow(-1, i);
}
REP(i, N) {
cout << (d - d2 * 2) * pow(-1, i) << " ";
d2 = d2 + A[i] * pow(-1, i);
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0, i##_l = (n); i < i##_l; i++)
int main() {
int N;
cin >> N;
vector<int> A(N);
int d = 0, d2 = 0;
REP(i, N) {
cin >> A[i];
d += A[i] * pow(-1, i);
}
REP(i, N) {
cout << (d - d2 * 2) * (int)pow(-1, i) << " ";
d2 = d2 + A[i] * pow(-1, i);
}
return 0;
}
| [
"type_conversion.add"
] | 793,371 | 793,372 | u840105874 | cpp |
p02984 | #pragma GCC optimize("O3")
#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
using QWORD = uint64_t;
using SQWORD = int64_t;
using DWORD = uint32_t;
using SDWORD = int32_t;
using WORD = uint16_t;
using SWORD = int16_t;
using BYTE = uint8_t;
using SBYTE = int8_t;
using DOUBLE = double;
using FLOAT = float;
#define MIN_SDWORD (-2147483648)
#define MAX_SDWORD (2147483647)
#define MIN_SBYTE (-128)
#define MAX_SBYTE (127)
#define MIN_SQWORD (0x8000000000000000)
#define MAX_SQWORD (0x7FFFFFFFFFFFFFFF)
#define MAX_QWORD (0xFFFFFFFFFFFFFFFF)
#define MAX_DWORD (0xFFFFFFFF)
#define MAX_WORD (0xFFFF)
#define MAX_BYTE (0xFF)
#define MAX_DOUBLE (1.0e+308)
#define DOUBLE_EPS (1.0e-12)
#define MIN_DOUBLE_N (-1.0e+308)
#define ArrayLength(a) (sizeof(a) / sizeof(a[0]))
static inline DOUBLE MAX(DOUBLE a, DOUBLE b) { return a > b ? a : b; }
static inline QWORD MAX(QWORD a, QWORD b) { return a > b ? a : b; }
static inline DWORD MAX(DWORD a, DWORD b) { return a > b ? a : b; }
static inline SDWORD MAX(SDWORD a, SDWORD b) { return a > b ? a : b; }
static inline DOUBLE MIN(DOUBLE a, DOUBLE b) { return a < b ? a : b; }
static inline QWORD MIN(QWORD a, QWORD b) { return a < b ? a : b; }
static inline DWORD MIN(DWORD a, DWORD b) { return a < b ? a : b; }
static inline SDWORD MIN(SDWORD a, SDWORD b) { return a < b ? a : b; }
#define BYTE_BITS (8)
#define WORD_BITS (16)
#define DWORD_BITS (32)
#define QWORD_BITS (64)
static inline void inputStringSpSeparated(char *pcStr) {
char *pcCur = pcStr;
for (;;) {
char c = getchar();
if (('\n' == c) || (EOF == c) || (' ' == c)) {
break;
}
*pcCur = c;
pcCur++;
}
*pcCur = '\0';
}
static inline void inputString(char *pcStr) {
char *pcCur = pcStr;
for (;;) {
char c = getchar();
if (('\n' == c) || (EOF == c)) {
break;
}
*pcCur = c;
pcCur++;
}
*pcCur = '\0';
}
static inline SQWORD inputSQWORD(void) {
SQWORD sqNumber = 0;
SQWORD sqMultiplier = 1;
bool bRead = false;
for (;;) {
char c = getchar();
if (!bRead) {
if ('-' == c) {
sqMultiplier = -1;
}
}
if (('0' <= c) && (c <= '9')) {
sqNumber *= 10LL;
sqNumber += (SQWORD)(c - '0');
bRead = true;
} else {
if (bRead) {
return sqNumber * sqMultiplier;
}
}
}
}
static inline SDWORD inputSDWORD(void) {
SDWORD lNumber = 0;
SDWORD lMultiplier = 1;
bool bRead = false;
for (;;) {
char c = getchar();
if (!bRead) {
if ('-' == c) {
lMultiplier = -1;
}
}
if (('0' <= c) && (c <= '9')) {
lNumber *= 10;
lNumber += (c - '0');
bRead = true;
} else {
if (bRead) {
return lNumber * lMultiplier;
}
}
}
}
static inline DOUBLE inputFP(void) {
DOUBLE dInt = 0.0;
DOUBLE dFrac = 0.0;
DOUBLE dMultiplier = 1.0;
DWORD dwFpCnt = 0;
DOUBLE *pdCur = &dInt;
bool bRead = false;
for (;;) {
char c = getchar();
if (!bRead) {
if ('-' == c) {
dMultiplier = -1;
}
}
if ('.' == c) {
pdCur = &dFrac;
} else if (('0' <= c) && (c <= '9')) {
(*pdCur) *= 10;
(*pdCur) += (DOUBLE)(c - '0');
bRead = true;
if (pdCur == &dFrac) {
dwFpCnt++;
}
} else {
if (bRead) {
return dMultiplier *
(dInt + dFrac / (pow((DOUBLE)10.0, (DOUBLE)dwFpCnt)));
}
}
}
}
/**
* mod による操作ライブラリ
*/
#define ANS_MOD (1000000007LL)
static SQWORD addMod(SQWORD x, SQWORD y) { return (x + y) % ANS_MOD; }
static SQWORD subMod(SQWORD x, SQWORD y) { return (x - y + ANS_MOD) % ANS_MOD; }
static SQWORD mulMod(SQWORD x, SQWORD y) { return (x * y) % ANS_MOD; }
static SQWORD powMod(SQWORD x, SQWORD e) {
SQWORD v = 1;
for (; e; x = mulMod(x, x), e >>= 1) {
if (e & 1) {
v = mulMod(v, x);
}
}
return v;
}
static SQWORD divMod(SQWORD x, SQWORD y) {
return mulMod(x, powMod(y, ANS_MOD - 2));
}
static SQWORD combMod(SQWORD n, SQWORD k) {
SQWORD v = 1;
for (SQWORD i = 1; i <= k; i++) {
v = divMod(mulMod(v, n - i + 1), i);
}
return v;
}
/*----------------------------------------------*/
int main(void) {
SQWORD sqInput_N = inputSQWORD();
vector<SQWORD> vecsqA;
SQWORD sqSumA = 0;
vecsqA.emplace_back(0);
for (SQWORD sqIdx = 0; sqIdx < sqInput_N; sqIdx++) {
SQWORD sqInput_A = inputSQWORD();
vecsqA.emplace_back(sqInput_A);
sqSumA += sqInput_A;
}
SQWORD sqSumX = sqSumA / 2;
SQWORD sqCumSumE = 0;
for (SQWORD sqIdx = 2; sqIdx <= sqInput_N - 1; sqIdx += 2) {
sqCumSumE += vecsqA[sqIdx];
}
SQWORD sqX = sqSumX - sqCumSumE;
for (SQWORD sqIdx = 1; sqIdx <= sqInput_N; sqIdx++) {
printf("%lld ", sqX);
sqX = vecsqA[sqIdx] - sqX;
}
printf("\n");
return 0;
} | #pragma GCC optimize("O3")
#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
using QWORD = uint64_t;
using SQWORD = int64_t;
using DWORD = uint32_t;
using SDWORD = int32_t;
using WORD = uint16_t;
using SWORD = int16_t;
using BYTE = uint8_t;
using SBYTE = int8_t;
using DOUBLE = double;
using FLOAT = float;
#define MIN_SDWORD (-2147483648)
#define MAX_SDWORD (2147483647)
#define MIN_SBYTE (-128)
#define MAX_SBYTE (127)
#define MIN_SQWORD (0x8000000000000000)
#define MAX_SQWORD (0x7FFFFFFFFFFFFFFF)
#define MAX_QWORD (0xFFFFFFFFFFFFFFFF)
#define MAX_DWORD (0xFFFFFFFF)
#define MAX_WORD (0xFFFF)
#define MAX_BYTE (0xFF)
#define MAX_DOUBLE (1.0e+308)
#define DOUBLE_EPS (1.0e-12)
#define MIN_DOUBLE_N (-1.0e+308)
#define ArrayLength(a) (sizeof(a) / sizeof(a[0]))
static inline DOUBLE MAX(DOUBLE a, DOUBLE b) { return a > b ? a : b; }
static inline QWORD MAX(QWORD a, QWORD b) { return a > b ? a : b; }
static inline DWORD MAX(DWORD a, DWORD b) { return a > b ? a : b; }
static inline SDWORD MAX(SDWORD a, SDWORD b) { return a > b ? a : b; }
static inline DOUBLE MIN(DOUBLE a, DOUBLE b) { return a < b ? a : b; }
static inline QWORD MIN(QWORD a, QWORD b) { return a < b ? a : b; }
static inline DWORD MIN(DWORD a, DWORD b) { return a < b ? a : b; }
static inline SDWORD MIN(SDWORD a, SDWORD b) { return a < b ? a : b; }
#define BYTE_BITS (8)
#define WORD_BITS (16)
#define DWORD_BITS (32)
#define QWORD_BITS (64)
static inline void inputStringSpSeparated(char *pcStr) {
char *pcCur = pcStr;
for (;;) {
char c = getchar();
if (('\n' == c) || (EOF == c) || (' ' == c)) {
break;
}
*pcCur = c;
pcCur++;
}
*pcCur = '\0';
}
static inline void inputString(char *pcStr) {
char *pcCur = pcStr;
for (;;) {
char c = getchar();
if (('\n' == c) || (EOF == c)) {
break;
}
*pcCur = c;
pcCur++;
}
*pcCur = '\0';
}
static inline SQWORD inputSQWORD(void) {
SQWORD sqNumber = 0;
SQWORD sqMultiplier = 1;
bool bRead = false;
for (;;) {
char c = getchar();
if (!bRead) {
if ('-' == c) {
sqMultiplier = -1;
}
}
if (('0' <= c) && (c <= '9')) {
sqNumber *= 10LL;
sqNumber += (SQWORD)(c - '0');
bRead = true;
} else {
if (bRead) {
return sqNumber * sqMultiplier;
}
}
}
}
static inline SDWORD inputSDWORD(void) {
SDWORD lNumber = 0;
SDWORD lMultiplier = 1;
bool bRead = false;
for (;;) {
char c = getchar();
if (!bRead) {
if ('-' == c) {
lMultiplier = -1;
}
}
if (('0' <= c) && (c <= '9')) {
lNumber *= 10;
lNumber += (c - '0');
bRead = true;
} else {
if (bRead) {
return lNumber * lMultiplier;
}
}
}
}
static inline DOUBLE inputFP(void) {
DOUBLE dInt = 0.0;
DOUBLE dFrac = 0.0;
DOUBLE dMultiplier = 1.0;
DWORD dwFpCnt = 0;
DOUBLE *pdCur = &dInt;
bool bRead = false;
for (;;) {
char c = getchar();
if (!bRead) {
if ('-' == c) {
dMultiplier = -1;
}
}
if ('.' == c) {
pdCur = &dFrac;
} else if (('0' <= c) && (c <= '9')) {
(*pdCur) *= 10;
(*pdCur) += (DOUBLE)(c - '0');
bRead = true;
if (pdCur == &dFrac) {
dwFpCnt++;
}
} else {
if (bRead) {
return dMultiplier *
(dInt + dFrac / (pow((DOUBLE)10.0, (DOUBLE)dwFpCnt)));
}
}
}
}
/**
* mod による操作ライブラリ
*/
#define ANS_MOD (1000000007LL)
static SQWORD addMod(SQWORD x, SQWORD y) { return (x + y) % ANS_MOD; }
static SQWORD subMod(SQWORD x, SQWORD y) { return (x - y + ANS_MOD) % ANS_MOD; }
static SQWORD mulMod(SQWORD x, SQWORD y) { return (x * y) % ANS_MOD; }
static SQWORD powMod(SQWORD x, SQWORD e) {
SQWORD v = 1;
for (; e; x = mulMod(x, x), e >>= 1) {
if (e & 1) {
v = mulMod(v, x);
}
}
return v;
}
static SQWORD divMod(SQWORD x, SQWORD y) {
return mulMod(x, powMod(y, ANS_MOD - 2));
}
static SQWORD combMod(SQWORD n, SQWORD k) {
SQWORD v = 1;
for (SQWORD i = 1; i <= k; i++) {
v = divMod(mulMod(v, n - i + 1), i);
}
return v;
}
/*----------------------------------------------*/
int main(void) {
SQWORD sqInput_N = inputSQWORD();
vector<SQWORD> vecsqA;
SQWORD sqSumA = 0;
vecsqA.emplace_back(0);
for (SQWORD sqIdx = 0; sqIdx < sqInput_N; sqIdx++) {
SQWORD sqInput_A = inputSQWORD();
vecsqA.emplace_back(sqInput_A);
sqSumA += sqInput_A;
}
SQWORD sqSumX = sqSumA / 2;
SQWORD sqCumSumE = 0;
for (SQWORD sqIdx = 2; sqIdx <= sqInput_N - 1; sqIdx += 2) {
sqCumSumE += vecsqA[sqIdx];
}
SQWORD sqX = sqSumX - sqCumSumE;
for (SQWORD sqIdx = 1; sqIdx <= sqInput_N; sqIdx++) {
printf("%lld ", sqX * 2);
sqX = vecsqA[sqIdx] - sqX;
}
printf("\n");
return 0;
} | [
"expression.operation.binary.add"
] | 793,382 | 793,383 | u487476769 | cpp |
p02984 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int64_t, int64_t> pll;
#define rep(i, a, b) for (int64_t i = (a); i < (b); i++)
#define REP(i, n) rep(i, 0, n)
int main() {
int N;
cin >> N;
vector<int> a(N);
int sum = 0, sum1 = 0;
REP(i, N) {
cin >> a[i];
sum += a[i];
if (i % 2)
sum += a[i];
}
int ans = sum - 2 * sum1;
cout << ans;
REP(i, N) {
ans = a[i] * -ans;
cout << " " << ans;
}
cout << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int64_t, int64_t> pll;
#define rep(i, a, b) for (int64_t i = (a); i < (b); i++)
#define REP(i, n) rep(i, 0, n)
int main() {
int N;
cin >> N;
vector<int> a(N);
int sum = 0, sum1 = 0;
REP(i, N) {
cin >> a[i];
sum += a[i];
if (i % 2)
sum1 += a[i];
}
int ans = sum - 2 * sum1;
cout << ans;
REP(i, N - 1) {
ans = a[i] * 2 - ans;
cout << " " << ans;
}
cout << endl;
} | [
"assignment.variable.change",
"identifier.change"
] | 793,388 | 793,389 | u973991908 | cpp |
p02984 | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
using itn = int;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
int main() {
int n;
cin >> n;
vector<ll> a(n + 1);
ll sum = 0;
ll sum_g = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
sum += a[i];
if (i % 2 == 0)
sum_g += a[i];
}
vector<ll> dp(n + 1);
dp[1] = sum - 2 * sum_g;
for (int i = 1; i <= n; i++) {
dp[i + 1] = 2 * a[i] - dp[i];
}
for (int i = 1; i <= n; i++) {
cout << dp[i];
}
return 0;
/*
vector<ll> dp(n+10);
for (int i = 0; i <= a[1]; i++) {
dp[0] = i;
for (int j = 1; j <= n; j++) {
dp[j] = a[j] - dp[j-1];
}
if (dp[n] == dp[0]) {
for (int k = 0; k < n; k++) {
cout << dp[k] * 2;
}
return 0;
}
}
*/
} | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
using itn = int;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
int main() {
int n;
cin >> n;
vector<ll> a(n + 1);
ll sum = 0;
ll sum_g = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
sum += a[i];
if (i % 2 == 0)
sum_g += a[i];
}
vector<ll> dp(n + 1);
dp[1] = sum - 2 * sum_g;
for (int i = 1; i <= n; i++) {
dp[i + 1] = 2 * a[i] - dp[i];
}
for (int i = 1; i <= n; i++) {
cout << dp[i] << " ";
}
return 0;
/*
vector<ll> dp(n+10);
for (int i = 0; i <= a[1]; i++) {
dp[0] = i;
for (int j = 1; j <= n; j++) {
dp[j] = a[j] - dp[j-1];
}
if (dp[n] == dp[0]) {
for (int k = 0; k < n; k++) {
cout << dp[k] * 2;
}
return 0;
}
}
*/
} | [
"io.output.change"
] | 793,390 | 793,391 | u538125576 | cpp |
p02984 | #include <iostream>
using namespace std;
int main() {
int N;
cin >> N;
int A[N], W[N];
for (int i = 0; i < N; i++) {
cin >> A[i];
}
int x = 0;
for (int i = 0; i < N; i++) {
if (i % 2 == 0)
x += A[i];
else {
x += -1 * A[i];
}
}
W[0] = x;
for (int i = 1; i < N; i++) {
W[i] = 2 * A[i - 1] - W[i - 1];
}
for (int i = 0; i < N; i++) {
cout << W[i];
}
} | #include <iostream>
using namespace std;
int main() {
int N;
cin >> N;
int A[N], W[N];
for (int i = 0; i < N; i++) {
cin >> A[i];
}
int x = 0;
for (int i = 0; i < N; i++) {
if (i % 2 == 0)
x += A[i];
else {
x += -1 * A[i];
}
}
W[0] = x;
for (int i = 1; i < N; i++) {
W[i] = 2 * A[i - 1] - W[i - 1];
}
for (int i = 0; i < N; i++) {
cout << W[i] << ' ';
}
} | [
"io.output.change"
] | 793,392 | 793,393 | u958984779 | cpp |
p02984 | #include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
long long a[n];
long long sum = 0, sum2 = 0;
for (long long i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
a[i] *= 2;
if (i != 0 && i % 2 == 0) {
sum2 += a[i];
}
}
long long m[n];
m[0] = sum - sum2;
for (long long i = 1; i < n; i++) {
m[i] = a[i - 1] - m[i - 1];
}
for (long long i = 0; i < n - 1; i++) {
cout << m[i] << ' ';
}
cout << m[n - 1] << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
long long a[n];
long long sum = 0, sum2 = 0;
for (long long i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
a[i] *= 2;
if (i % 2 == 1) {
sum2 += a[i];
}
}
long long m[n];
m[0] = sum - sum2;
for (long long i = 1; i < n; i++) {
m[i] = a[i - 1] - m[i - 1];
}
for (long long i = 0; i < n - 1; i++) {
cout << m[i] << ' ';
}
cout << m[n - 1] << endl;
return 0;
}
| [
"control_flow.loop.for.condition.change",
"expression.operation.binary.remove",
"literal.number.change",
"control_flow.branch.if.condition.change"
] | 793,402 | 793,403 | u954976049 | cpp |
p02984 | // abc133_d.cpp
// Sun Jul 7 20:47:41 2019
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll = long long;
typedef pair<int, int> P;
int main() {
int n;
cin >> n;
ll a[n];
ll total = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
total += a[i];
}
ll ans[n];
fill(ans, ans + n, 0);
int temp = 0;
for (int i = 1; i < n - 1; i = i + 2) {
temp += a[i];
}
ans[0] = total - 2 * temp;
for (int i = 1; i < n; i++) {
ans[i] = a[i - 1] * 2 - ans[i - 1];
}
for (int i = 0; i < n; i++) {
cout << ans[i] << " ";
}
printf("\n");
} | // abc133_d.cpp
// Sun Jul 7 20:47:41 2019
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll = long long;
typedef pair<int, int> P;
int main() {
int n;
cin >> n;
ll a[n];
ll total = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
total += a[i];
}
ll ans[n];
fill(ans, ans + n, 0);
ll temp = 0;
for (int i = 1; i < n - 1; i = i + 2) {
temp += a[i];
}
ans[0] = total - 2 * temp;
for (int i = 1; i < n; i++) {
ans[i] = a[i - 1] * 2 - ans[i - 1];
}
for (int i = 0; i < n; i++) {
cout << ans[i] << " ";
}
printf("\n");
} | [
"variable_declaration.type.change"
] | 793,411 | 793,412 | u628871447 | cpp |
p02987 | #include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <string>
#include <vector>
#define reps(i, s, n) for (int(i) = (s); (i) < (n); (i)++)
#define rep(i, n) reps(i, 0, n)
using namespace std;
using ll = long long;
int main() {
string s;
cin >> s;
map<int, int> mp;
rep(i, 4) { mp[s[i] - 'A']++; }
for (auto e : mp) {
if (e.second != 2) {
cout << "NO" << endl;
return 0;
}
}
cout << "YES" << endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <string>
#include <vector>
#define reps(i, s, n) for (int(i) = (s); (i) < (n); (i)++)
#define rep(i, n) reps(i, 0, n)
using namespace std;
using ll = long long;
int main() {
string s;
cin >> s;
map<int, int> mp;
rep(i, 4) { mp[s[i] - 'A']++; }
for (auto e : mp) {
if (e.second != 2) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
return 0;
} | [
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 793,421 | 793,422 | u704411633 | cpp |
p02987 | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
int main() {
string s, ans = "No";
cin >> s;
sort(s.begin(), s.end());
if (s[0] == s[1] or s[1] != s[2] or s[2] == s[3]) {
ans = "Yes";
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
int main() {
string s, ans = "No";
cin >> s;
sort(s.begin(), s.end());
if (s[0] == s[1] and s[1] != s[2] and s[2] == s[3]) {
ans = "Yes";
}
cout << ans << endl;
return 0;
} | [
"identifier.change",
"control_flow.branch.if.condition.change",
"control_flow.return.add",
"control_flow.return.0.add"
] | 793,431 | 793,432 | u897135531 | cpp |
p02987 | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
if (s.at(0) == s.at(1) && s.at(2) == s.at(3) && s.at(0) != s.at(2)) {
cout << "Yes" << endl;
} else if (s.at(0) != s.at(1) && s.at(0) == s.at(2) && s.at(1) == s.at(3)) {
cout << "Yes" << endl;
} else if (s.at(0) == s.at(3) && s.at(2) == s.at(3) && s.at(0) != s.at(2)) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
if (s.at(0) == s.at(1) && s.at(2) == s.at(3) && s.at(0) != s.at(2)) {
cout << "Yes" << endl;
} else if (s.at(0) != s.at(1) && s.at(0) == s.at(2) && s.at(1) == s.at(3)) {
cout << "Yes" << endl;
} else if (s.at(0) == s.at(3) && s.at(1) == s.at(2) && s.at(0) != s.at(2)) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
| [
"literal.number.change",
"control_flow.branch.if.condition.change"
] | 793,433 | 793,434 | u758405447 | cpp |
p02987 | #include <bits/stdc++.h>
using namespace std;
int main() {
string a;
cin >> a;
if (a[0] == a[1] && a[1] == a[2] && a[2] == a[3])
cout << "Yes" << endl;
else if (a[0] == a[2] && a[2] == a[1] && a[1] == a[3])
cout << "Yes" << endl;
else if (a[0] == a[3] && a[3] == a[1] && a[1] == a[2])
cout << "Yes" << endl;
else
cout << "No" << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
string a;
cin >> a;
if (a[0] == a[1] && a[1] != a[2] && a[2] == a[3])
cout << "Yes" << endl;
else if (a[0] == a[2] && a[2] != a[1] && a[1] == a[3])
cout << "Yes" << endl;
else if (a[0] == a[3] && a[3] != a[1] && a[1] == a[2])
cout << "Yes" << endl;
else
cout << "No" << endl;
}
| [
"misc.opposites",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 793,435 | 793,436 | u458713847 | cpp |
p02987 | #include <algorithm>
#include <array>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdint.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;
// BDD,ZDD,kdtree, bdtree,bicalc, bolonoy,
// doloney,chinesemod,segmenttree,daikusutora, saidairyuu, 2bugurahu,
// heirokenshutu, topologicalsort, kyourenketuseibun
#define PRI(s) cout << s << endl
#define PRIY PRI("Yes")
#define PRIN PRI("No")
int main() {
string s;
char m[2];
int c[2] = {1, 0};
cin >> s;
m[0] = s[0];
bool full = false;
for (int i = 1; i < 4; ++i) {
if (full) {
if (s[i] == m[0])
c[0]++;
else if (s[i] == m[1])
c[1]++;
else {
PRIN;
return 0;
}
} else {
if (s[i] == m[0])
c[0]++;
else {
m[1] = s[i];
c[1]++;
}
}
}
if (c[0] == 2 && c[1] == 2)
PRIY;
else
PRIN;
return 0;
} | #include <algorithm>
#include <array>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdint.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;
// BDD,ZDD,kdtree, bdtree,bicalc, bolonoy,
// doloney,chinesemod,segmenttree,daikusutora, saidairyuu, 2bugurahu,
// heirokenshutu, topologicalsort, kyourenketuseibun
#define PRI(s) cout << s << endl
#define PRIY PRI("Yes")
#define PRIN PRI("No")
int main() {
string s;
char m[2];
int c[2] = {1, 0};
cin >> s;
m[0] = s[0];
bool full = false;
for (int i = 1; i < 4; ++i) {
if (full) {
if (s[i] == m[0])
c[0]++;
else if (s[i] == m[1])
c[1]++;
else {
PRIN;
return 0;
}
} else {
if (s[i] == m[0])
c[0]++;
else {
m[1] = s[i];
c[1]++;
full = true;
}
}
}
if (c[0] == 2 && c[1] == 2)
PRIY;
else
PRIN;
return 0;
} | [
"assignment.add"
] | 793,438 | 793,439 | u539145601 | cpp |
p02987 | #include <algorithm>
#include <iostream>
#include <string.h>
using namespace std;
int main() {
string s;
int cnt = 0;
cin >> s;
sort(s.begin(), s.end());
for (int i = 0; i < s.length() - 1; i++)
if (s[i] == s[i + 1])
cnt++;
if (cnt == 2)
cout << "YES";
else
cout << "NO";
}
| #include <algorithm>
#include <iostream>
#include <string.h>
using namespace std;
int main() {
string s;
int cnt = 0;
cin >> s;
sort(s.begin(), s.end());
for (int i = 0; i < s.length() - 1; i++)
if (s[i] == s[i + 1])
cnt++;
if (cnt == 2)
cout << "Yes";
else
cout << "No";
}
| [
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 793,442 | 793,443 | u630995645 | cpp |
p02987 | #include <algorithm>
#include <iostream>
#include <string.h>
using namespace std;
int main() {
string s;
int cnt = 0;
cin >> s;
sort(s.begin(), s.end());
for (int i = 0; i < s.length() - 1; i++)
if (s[i] != s[i + 1])
cnt++;
if (cnt == 1)
cout << "YES";
else
cout << "NO";
}
| #include <algorithm>
#include <iostream>
#include <string.h>
using namespace std;
int main() {
string s;
int cnt = 0;
cin >> s;
sort(s.begin(), s.end());
for (int i = 0; i < s.length() - 1; i++)
if (s[i] == s[i + 1])
cnt++;
if (cnt == 2)
cout << "Yes";
else
cout << "No";
}
| [
"misc.opposites",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change",
"literal.number.change",
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 793,444 | 793,443 | u630995645 | cpp |
p02987 | #include <algorithm>
#include <iostream>
#include <string.h>
using namespace std;
int main() {
string s;
int cnt = 0;
cin >> s;
sort(s.begin(), s.end());
for (int i = 0; i < s.length() - 1; i++)
if (s[i] != s[i + 1])
cnt++;
if (cnt < 2)
cout << "YES";
else
cout << "NO";
}
| #include <algorithm>
#include <iostream>
#include <string.h>
using namespace std;
int main() {
string s;
int cnt = 0;
cin >> s;
sort(s.begin(), s.end());
for (int i = 0; i < s.length() - 1; i++)
if (s[i] == s[i + 1])
cnt++;
if (cnt == 2)
cout << "Yes";
else
cout << "No";
}
| [
"misc.opposites",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change",
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 793,445 | 793,443 | u630995645 | cpp |
p02987 | #include <algorithm>
#include <iostream>
using namespace std;
int main() {
string s;
cin >> s;
sort(s.begin(), s.end());
if (s[0] == s[1] && s[1] == s[2] && s[0] != s[2]) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
}
| #include <algorithm>
#include <iostream>
using namespace std;
int main() {
string s;
cin >> s;
sort(s.begin(), s.end());
if (s[0] == s[1] && s[1] != s[2] && s[2] == s[3]) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
}
| [
"misc.opposites",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change",
"literal.number.change",
"variable_access.subscript.index.change"
] | 793,447 | 793,448 | u347471422 | cpp |
p02987 | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
string s;
cin >> s;
if ((s[0] == s[1] && s[2] == s[3] && s[0] != s[2]) ||
(s[0] == s[2] && s[1] == s[3] && s[0] != s[1]) ||
(s[0] == s[3] && s[1] == s[1] && s[0] != s[1]))
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
string s;
cin >> s;
if ((s[0] == s[1] && s[2] == s[3] && s[0] != s[2]) ||
(s[0] == s[2] && s[1] == s[3] && s[0] != s[1]) ||
(s[0] == s[3] && s[1] == s[2] && s[0] != s[1]))
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
} | [
"literal.number.change",
"variable_access.subscript.index.change",
"control_flow.branch.if.condition.change"
] | 793,453 | 793,454 | u044960702 | cpp |
p02987 | #include <cmath>
#include <iostream>
#include <string>
using namespace std;
int main() {
string a;
cin >> a;
if (a[0] == a[1] && a[2] == a[3] && a[0] != a[2]) {
cout << "Yes";
}
if (a[0] == a[2] && a[1] == a[3] && a[0] != a[3]) {
cout << "Yes";
}
if (a[0] == a[3] && a[2] == a[1] && a[0] != a[2]) {
cout << "Yes";
} else {
cout << "No";
}
} | #include <cmath>
#include <iostream>
#include <string>
using namespace std;
int main() {
string a;
cin >> a;
if (a[0] == a[1] && a[2] == a[3] && a[0] != a[2]) {
cout << "Yes";
} else if (a[0] == a[2] && a[1] == a[3] && a[0] != a[3]) {
cout << "Yes";
} else if (a[0] == a[3] && a[2] == a[1] && a[0] != a[2]) {
cout << "Yes";
} else {
cout << "No";
}
} | [
"control_flow.branch.else_if.replace.add",
"control_flow.branch.if.replace.remove"
] | 793,455 | 793,456 | u860150008 | cpp |
p02987 | #include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
using Pii = pair<int, int>;
using Pil = pair<int, ll>;
using Pll = pair<ll, ll>;
using Pid = pair<int, ld>;
using Pis = pair<int, string>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repm(i, s, n) for (int i = s; i < n; i++)
const int INF = 1 << 30;
const ll INF_L = 1LL << 60;
const int MOD = 1e9 + 7; // 998244353;
void cout_ynl(bool b) { cout << (b ? "Yes" : "No") << endl; }
void cout_YNU(bool b) { cout << (b ? "YES" : "NO") << endl; }
// ----------------------------------------------------------------
// String Functions
// ----------------------------------------------------------------
int ctoi(char c) {
if (isdigit(c))
return c - '0';
else if (islower(c))
return c - 'a';
else if (isupper(c))
return c - 'A';
else
return -1;
}
char itocd(int i) {
char c = i + '0';
if (isdigit(c))
return c;
else
return 0x00;
}
char itocl(int i) {
char c = i + 'a';
if (islower(c))
return c;
else
return 0x00;
}
char itocu(int i) {
char c = i + 'A';
if (isupper(c))
return c;
else
return 0x00;
}
// ----------------------------------------------------------------
// ----------------------------------------------------------------
// Dynamical Programming
// ----------------------------------------------------------------
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
// ----------------------------------------------------------------
// ----------------------------------------------------------------
// Graph Theory
// ----------------------------------------------------------------
vector<vector<int>> adjMat;
vector<set<Pii>> adjList;
void graphDijkstra() {}
void graphBellmanFord() {}
void graphWarshallFloyd() {}
// ----------------------------------------------------------------
// ----------------------------------------------------------------
// Mathematical Functions
// ----------------------------------------------------------------
ll gcd(ll A, ll B) {
if (A % B == 0) {
return (B);
} else {
return (gcd(B, A % B));
}
}
ll lcm(ll A, ll B) { return A * B / gcd(A, B); }
ll divTimes(ll N, ll D) {
ll res = 0;
while (N % D == 0) {
N /= D;
res++;
}
return res;
}
ll powMod(ll B, ll P) {
if (P == 0)
return 1;
if (P % 2 == 0) {
ll t = powMod(B, P / 2);
return t * t % MOD;
}
return B * powMod(B, P - 1) % MOD;
}
/* ----------------------------------
Factorial, Permutation, Combination
---------------------------------- */
const int FAC_INIT_SIZE = 1e6 + 9;
vector<ll> fac, finv, inv;
void factModInit() {
fac.resize(FAC_INIT_SIZE);
finv.resize(FAC_INIT_SIZE);
inv.resize(FAC_INIT_SIZE);
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < FAC_INIT_SIZE; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
ll factMod(ll N) { return fac[N] % MOD; }
ll factInvMod(ll N) { return finv[N] % MOD; }
ll permMod(ll N, ll K) {
if (N < 0 || K < 0 || N < K)
return 0;
else
return factMod(N) * factInvMod(N - K) % MOD;
}
ll combMod(ll N, ll K) {
if (N < 0 || K < 0 || N < K)
return 0;
else if (N < FAC_INIT_SIZE) {
return factMod(N) * (factInvMod(K) * factInvMod(N - K) % MOD) % MOD;
} else {
ll ans = 1;
ll Ks = K < N - K ? K : N - K;
for (ll i = N; i > N - Ks; i--) {
ans *= i;
ans %= MOD;
}
return ans * factInvMod(Ks) % MOD;
}
}
/* ----------------------------------
Sieve of Atkin & Bernstein
---------------------------------- */
vector<bool> sieve;
void sieveInit(ll size) {
sieve.clear();
if (size < 0 || size > INF)
return;
int ss = (int)size + 9;
int ssq = sqrt(ss + 0.1);
sieve.resize(ss);
sieve[2] = sieve[3] = true;
int n = 0;
for (int z = 1; z <= 5; z += 4) {
for (int y = z; y <= ssq; y += 6) {
for (int x = 1; x <= ssq && (n = 4 * x * x + y * y) < ss; x++)
sieve[n] = !sieve[n];
for (int x = y + 1; x <= ssq && (n = 3 * x * x - y * y) < ss; x += 2)
sieve[n] = !sieve[n];
}
}
for (int z = 2; z <= 4; z += 2) {
for (int y = z; y <= ssq; y += 6) {
for (int x = 1; x <= ssq && (n = 3 * x * x + y * y) < ss; x += 2)
sieve[n] = !sieve[n];
for (int x = y + 1; x <= ssq && (n = 3 * x * x - y * y) < ss; x += 2)
sieve[n] = !sieve[n];
}
}
for (int z = 1; z <= 2; z++) {
for (int y = 3; y <= ssq; y += 6) {
for (int x = z; x <= ssq && (n = 4 * x * x + y * y) < ss; x += 3)
sieve[n] = !sieve[n];
}
}
for (int k = 5; k <= ssq; k++)
if (sieve[k])
for (int n = k * k; n < ss; n += k * k)
sieve[n] = false;
}
/* ----------------------------------
Prime Factorization
---------------------------------- */
map<ll, map<ll, ll>> primeFactorMap;
map<ll, set<ll>> primeFactorSet;
void primeFactorizeInit() {
primeFactorMap.clear();
primeFactorSet.clear();
}
void primeFactorize(ll N) {
if (N < 0 || N > INF_L)
return;
ll Nc = N, Nsq = sqrt(N + 0.1);
for (int k = 2; k <= Nsq; k++) {
ll dt = 0;
while (Nc % k == 0) {
dt++;
Nc /= k;
}
if (dt > 0)
primeFactorMap[N][k] = dt;
if (N % k == 0) {
primeFactorSet[N].insert(k);
primeFactorSet[N].insert(N / k);
}
}
if (Nc != 1)
primeFactorMap[N][Nc] = 1;
primeFactorSet[N].insert(1);
primeFactorSet[N].insert(N);
}
// ----------------------------------------------------------------
void solve() {
string S;
cin >> S;
vector<int> c(26, 0);
rep(i, 4) c[ctoi(S[i])]++;
bool fg = true;
rep(i, 26) {
if (c[i] != 0 || c[i] != 2) {
fg = false;
}
}
cout_ynl(fg);
}
int main() {
std::ifstream in("input.txt");
std::cin.rdbuf(in.rdbuf());
cin.tie(0);
ios::sync_with_stdio(false);
solve();
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
using Pii = pair<int, int>;
using Pil = pair<int, ll>;
using Pll = pair<ll, ll>;
using Pid = pair<int, ld>;
using Pis = pair<int, string>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repm(i, s, n) for (int i = s; i < n; i++)
const int INF = 1 << 30;
const ll INF_L = 1LL << 60;
const int MOD = 1e9 + 7; // 998244353;
void cout_ynl(bool b) { cout << (b ? "Yes" : "No") << endl; }
void cout_YNU(bool b) { cout << (b ? "YES" : "NO") << endl; }
// ----------------------------------------------------------------
// String Functions
// ----------------------------------------------------------------
int ctoi(char c) {
if (isdigit(c))
return c - '0';
else if (islower(c))
return c - 'a';
else if (isupper(c))
return c - 'A';
else
return -1;
}
char itocd(int i) {
char c = i + '0';
if (isdigit(c))
return c;
else
return 0x00;
}
char itocl(int i) {
char c = i + 'a';
if (islower(c))
return c;
else
return 0x00;
}
char itocu(int i) {
char c = i + 'A';
if (isupper(c))
return c;
else
return 0x00;
}
// ----------------------------------------------------------------
// ----------------------------------------------------------------
// Dynamical Programming
// ----------------------------------------------------------------
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
// ----------------------------------------------------------------
// ----------------------------------------------------------------
// Graph Theory
// ----------------------------------------------------------------
vector<vector<int>> adjMat;
vector<set<Pii>> adjList;
void graphDijkstra() {}
void graphBellmanFord() {}
void graphWarshallFloyd() {}
// ----------------------------------------------------------------
// ----------------------------------------------------------------
// Mathematical Functions
// ----------------------------------------------------------------
ll gcd(ll A, ll B) {
if (A % B == 0) {
return (B);
} else {
return (gcd(B, A % B));
}
}
ll lcm(ll A, ll B) { return A * B / gcd(A, B); }
ll divTimes(ll N, ll D) {
ll res = 0;
while (N % D == 0) {
N /= D;
res++;
}
return res;
}
ll powMod(ll B, ll P) {
if (P == 0)
return 1;
if (P % 2 == 0) {
ll t = powMod(B, P / 2);
return t * t % MOD;
}
return B * powMod(B, P - 1) % MOD;
}
/* ----------------------------------
Factorial, Permutation, Combination
---------------------------------- */
const int FAC_INIT_SIZE = 1e6 + 9;
vector<ll> fac, finv, inv;
void factModInit() {
fac.resize(FAC_INIT_SIZE);
finv.resize(FAC_INIT_SIZE);
inv.resize(FAC_INIT_SIZE);
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < FAC_INIT_SIZE; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
ll factMod(ll N) { return fac[N] % MOD; }
ll factInvMod(ll N) { return finv[N] % MOD; }
ll permMod(ll N, ll K) {
if (N < 0 || K < 0 || N < K)
return 0;
else
return factMod(N) * factInvMod(N - K) % MOD;
}
ll combMod(ll N, ll K) {
if (N < 0 || K < 0 || N < K)
return 0;
else if (N < FAC_INIT_SIZE) {
return factMod(N) * (factInvMod(K) * factInvMod(N - K) % MOD) % MOD;
} else {
ll ans = 1;
ll Ks = K < N - K ? K : N - K;
for (ll i = N; i > N - Ks; i--) {
ans *= i;
ans %= MOD;
}
return ans * factInvMod(Ks) % MOD;
}
}
/* ----------------------------------
Sieve of Atkin & Bernstein
---------------------------------- */
vector<bool> sieve;
void sieveInit(ll size) {
sieve.clear();
if (size < 0 || size > INF)
return;
int ss = (int)size + 9;
int ssq = sqrt(ss + 0.1);
sieve.resize(ss);
sieve[2] = sieve[3] = true;
int n = 0;
for (int z = 1; z <= 5; z += 4) {
for (int y = z; y <= ssq; y += 6) {
for (int x = 1; x <= ssq && (n = 4 * x * x + y * y) < ss; x++)
sieve[n] = !sieve[n];
for (int x = y + 1; x <= ssq && (n = 3 * x * x - y * y) < ss; x += 2)
sieve[n] = !sieve[n];
}
}
for (int z = 2; z <= 4; z += 2) {
for (int y = z; y <= ssq; y += 6) {
for (int x = 1; x <= ssq && (n = 3 * x * x + y * y) < ss; x += 2)
sieve[n] = !sieve[n];
for (int x = y + 1; x <= ssq && (n = 3 * x * x - y * y) < ss; x += 2)
sieve[n] = !sieve[n];
}
}
for (int z = 1; z <= 2; z++) {
for (int y = 3; y <= ssq; y += 6) {
for (int x = z; x <= ssq && (n = 4 * x * x + y * y) < ss; x += 3)
sieve[n] = !sieve[n];
}
}
for (int k = 5; k <= ssq; k++)
if (sieve[k])
for (int n = k * k; n < ss; n += k * k)
sieve[n] = false;
}
/* ----------------------------------
Prime Factorization
---------------------------------- */
map<ll, map<ll, ll>> primeFactorMap;
map<ll, set<ll>> primeFactorSet;
void primeFactorizeInit() {
primeFactorMap.clear();
primeFactorSet.clear();
}
void primeFactorize(ll N) {
if (N < 0 || N > INF_L)
return;
ll Nc = N, Nsq = sqrt(N + 0.1);
for (int k = 2; k <= Nsq; k++) {
ll dt = 0;
while (Nc % k == 0) {
dt++;
Nc /= k;
}
if (dt > 0)
primeFactorMap[N][k] = dt;
if (N % k == 0) {
primeFactorSet[N].insert(k);
primeFactorSet[N].insert(N / k);
}
}
if (Nc != 1)
primeFactorMap[N][Nc] = 1;
primeFactorSet[N].insert(1);
primeFactorSet[N].insert(N);
}
// ----------------------------------------------------------------
void solve() {
string S;
cin >> S;
vector<int> c(26, 0);
rep(i, 4) c[ctoi(S[i])]++;
bool fg = true;
// rep(i, 26) {cout << itocu(i) << c[i] << endl;}
rep(i, 26) {
if (c[i] != 0 && c[i] != 2) {
fg = false;
}
}
cout_ynl(fg);
}
int main() {
std::ifstream in("input.txt");
std::cin.rdbuf(in.rdbuf());
cin.tie(0);
ios::sync_with_stdio(false);
solve();
return 0;
}
| [
"misc.opposites",
"control_flow.branch.if.condition.change"
] | 793,457 | 793,458 | u947236878 | cpp |
p02987 | #include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
using Pii = pair<int, int>;
using Pil = pair<int, ll>;
using Pll = pair<ll, ll>;
using Pid = pair<int, ld>;
using Pis = pair<int, string>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repm(i, s, n) for (int i = s; i < n; i++)
const int INF = 1 << 30;
const ll INF_L = 1LL << 60;
const int MOD = 1e9 + 7; // 998244353;
void cout_ynl(bool b) { cout << (b ? "Yes" : "No") << endl; }
void cout_YNU(bool b) { cout << (b ? "YES" : "NO") << endl; }
// ----------------------------------------------------------------
// String Functions
// ----------------------------------------------------------------
int ctoi(char c) {
if (isdigit(c))
return c - '0';
else if (islower(c))
return c - 'a';
else if (isupper(c))
return c - 'A';
else
return -1;
}
char itocd(int i) {
char c = i + '0';
if (isdigit(c))
return c;
else
return 0x00;
}
char itocl(int i) {
char c = i + 'a';
if (islower(c))
return c;
else
return 0x00;
}
char itocu(int i) {
char c = i + 'A';
if (isupper(c))
return c;
else
return 0x00;
}
// ----------------------------------------------------------------
// ----------------------------------------------------------------
// Dynamical Programming
// ----------------------------------------------------------------
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
// ----------------------------------------------------------------
// ----------------------------------------------------------------
// Graph Theory
// ----------------------------------------------------------------
vector<vector<int>> adjMat;
vector<set<Pii>> adjList;
void graphDijkstra() {}
void graphBellmanFord() {}
void graphWarshallFloyd() {}
// ----------------------------------------------------------------
// ----------------------------------------------------------------
// Mathematical Functions
// ----------------------------------------------------------------
ll gcd(ll A, ll B) {
if (A % B == 0) {
return (B);
} else {
return (gcd(B, A % B));
}
}
ll lcm(ll A, ll B) { return A * B / gcd(A, B); }
ll divTimes(ll N, ll D) {
ll res = 0;
while (N % D == 0) {
N /= D;
res++;
}
return res;
}
ll powMod(ll B, ll P) {
if (P == 0)
return 1;
if (P % 2 == 0) {
ll t = powMod(B, P / 2);
return t * t % MOD;
}
return B * powMod(B, P - 1) % MOD;
}
/* ----------------------------------
Factorial, Permutation, Combination
---------------------------------- */
const int FAC_INIT_SIZE = 1e6 + 9;
vector<ll> fac, finv, inv;
void factModInit() {
fac.resize(FAC_INIT_SIZE);
finv.resize(FAC_INIT_SIZE);
inv.resize(FAC_INIT_SIZE);
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < FAC_INIT_SIZE; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
ll factMod(ll N) { return fac[N] % MOD; }
ll factInvMod(ll N) { return finv[N] % MOD; }
ll permMod(ll N, ll K) {
if (N < 0 || K < 0 || N < K)
return 0;
else
return factMod(N) * factInvMod(N - K) % MOD;
}
ll combMod(ll N, ll K) {
if (N < 0 || K < 0 || N < K)
return 0;
else if (N < FAC_INIT_SIZE) {
return factMod(N) * (factInvMod(K) * factInvMod(N - K) % MOD) % MOD;
} else {
ll ans = 1;
ll Ks = K < N - K ? K : N - K;
for (ll i = N; i > N - Ks; i--) {
ans *= i;
ans %= MOD;
}
return ans * factInvMod(Ks) % MOD;
}
}
/* ----------------------------------
Sieve of Atkin & Bernstein
---------------------------------- */
vector<bool> sieve;
void sieveInit(ll size) {
sieve.clear();
if (size < 0 || size > INF)
return;
int ss = (int)size + 9;
int ssq = sqrt(ss + 0.1);
sieve.resize(ss);
sieve[2] = sieve[3] = true;
int n = 0;
for (int z = 1; z <= 5; z += 4) {
for (int y = z; y <= ssq; y += 6) {
for (int x = 1; x <= ssq && (n = 4 * x * x + y * y) < ss; x++)
sieve[n] = !sieve[n];
for (int x = y + 1; x <= ssq && (n = 3 * x * x - y * y) < ss; x += 2)
sieve[n] = !sieve[n];
}
}
for (int z = 2; z <= 4; z += 2) {
for (int y = z; y <= ssq; y += 6) {
for (int x = 1; x <= ssq && (n = 3 * x * x + y * y) < ss; x += 2)
sieve[n] = !sieve[n];
for (int x = y + 1; x <= ssq && (n = 3 * x * x - y * y) < ss; x += 2)
sieve[n] = !sieve[n];
}
}
for (int z = 1; z <= 2; z++) {
for (int y = 3; y <= ssq; y += 6) {
for (int x = z; x <= ssq && (n = 4 * x * x + y * y) < ss; x += 3)
sieve[n] = !sieve[n];
}
}
for (int k = 5; k <= ssq; k++)
if (sieve[k])
for (int n = k * k; n < ss; n += k * k)
sieve[n] = false;
}
/* ----------------------------------
Prime Factorization
---------------------------------- */
map<ll, map<ll, ll>> primeFactorMap;
map<ll, set<ll>> primeFactorSet;
void primeFactorizeInit() {
primeFactorMap.clear();
primeFactorSet.clear();
}
void primeFactorize(ll N) {
if (N < 0 || N > INF_L)
return;
ll Nc = N, Nsq = sqrt(N + 0.1);
for (int k = 2; k <= Nsq; k++) {
ll dt = 0;
while (Nc % k == 0) {
dt++;
Nc /= k;
}
if (dt > 0)
primeFactorMap[N][k] = dt;
if (N % k == 0) {
primeFactorSet[N].insert(k);
primeFactorSet[N].insert(N / k);
}
}
if (Nc != 1)
primeFactorMap[N][Nc] = 1;
primeFactorSet[N].insert(1);
primeFactorSet[N].insert(N);
}
// ----------------------------------------------------------------
void solve() {
string S;
cin >> S;
vector<int> c(26, 0);
rep(i, 4) c[ctoi(S[i])]++;
bool fg = true;
rep(i, 26) if (c[i] != 0 || c[i] != 2) fg = false;
cout_ynl(fg);
}
int main() {
std::ifstream in("input.txt");
std::cin.rdbuf(in.rdbuf());
cin.tie(0);
ios::sync_with_stdio(false);
solve();
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
using Pii = pair<int, int>;
using Pil = pair<int, ll>;
using Pll = pair<ll, ll>;
using Pid = pair<int, ld>;
using Pis = pair<int, string>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repm(i, s, n) for (int i = s; i < n; i++)
const int INF = 1 << 30;
const ll INF_L = 1LL << 60;
const int MOD = 1e9 + 7; // 998244353;
void cout_ynl(bool b) { cout << (b ? "Yes" : "No") << endl; }
void cout_YNU(bool b) { cout << (b ? "YES" : "NO") << endl; }
// ----------------------------------------------------------------
// String Functions
// ----------------------------------------------------------------
int ctoi(char c) {
if (isdigit(c))
return c - '0';
else if (islower(c))
return c - 'a';
else if (isupper(c))
return c - 'A';
else
return -1;
}
char itocd(int i) {
char c = i + '0';
if (isdigit(c))
return c;
else
return 0x00;
}
char itocl(int i) {
char c = i + 'a';
if (islower(c))
return c;
else
return 0x00;
}
char itocu(int i) {
char c = i + 'A';
if (isupper(c))
return c;
else
return 0x00;
}
// ----------------------------------------------------------------
// ----------------------------------------------------------------
// Dynamical Programming
// ----------------------------------------------------------------
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
// ----------------------------------------------------------------
// ----------------------------------------------------------------
// Graph Theory
// ----------------------------------------------------------------
vector<vector<int>> adjMat;
vector<set<Pii>> adjList;
void graphDijkstra() {}
void graphBellmanFord() {}
void graphWarshallFloyd() {}
// ----------------------------------------------------------------
// ----------------------------------------------------------------
// Mathematical Functions
// ----------------------------------------------------------------
ll gcd(ll A, ll B) {
if (A % B == 0) {
return (B);
} else {
return (gcd(B, A % B));
}
}
ll lcm(ll A, ll B) { return A * B / gcd(A, B); }
ll divTimes(ll N, ll D) {
ll res = 0;
while (N % D == 0) {
N /= D;
res++;
}
return res;
}
ll powMod(ll B, ll P) {
if (P == 0)
return 1;
if (P % 2 == 0) {
ll t = powMod(B, P / 2);
return t * t % MOD;
}
return B * powMod(B, P - 1) % MOD;
}
/* ----------------------------------
Factorial, Permutation, Combination
---------------------------------- */
const int FAC_INIT_SIZE = 1e6 + 9;
vector<ll> fac, finv, inv;
void factModInit() {
fac.resize(FAC_INIT_SIZE);
finv.resize(FAC_INIT_SIZE);
inv.resize(FAC_INIT_SIZE);
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < FAC_INIT_SIZE; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
ll factMod(ll N) { return fac[N] % MOD; }
ll factInvMod(ll N) { return finv[N] % MOD; }
ll permMod(ll N, ll K) {
if (N < 0 || K < 0 || N < K)
return 0;
else
return factMod(N) * factInvMod(N - K) % MOD;
}
ll combMod(ll N, ll K) {
if (N < 0 || K < 0 || N < K)
return 0;
else if (N < FAC_INIT_SIZE) {
return factMod(N) * (factInvMod(K) * factInvMod(N - K) % MOD) % MOD;
} else {
ll ans = 1;
ll Ks = K < N - K ? K : N - K;
for (ll i = N; i > N - Ks; i--) {
ans *= i;
ans %= MOD;
}
return ans * factInvMod(Ks) % MOD;
}
}
/* ----------------------------------
Sieve of Atkin & Bernstein
---------------------------------- */
vector<bool> sieve;
void sieveInit(ll size) {
sieve.clear();
if (size < 0 || size > INF)
return;
int ss = (int)size + 9;
int ssq = sqrt(ss + 0.1);
sieve.resize(ss);
sieve[2] = sieve[3] = true;
int n = 0;
for (int z = 1; z <= 5; z += 4) {
for (int y = z; y <= ssq; y += 6) {
for (int x = 1; x <= ssq && (n = 4 * x * x + y * y) < ss; x++)
sieve[n] = !sieve[n];
for (int x = y + 1; x <= ssq && (n = 3 * x * x - y * y) < ss; x += 2)
sieve[n] = !sieve[n];
}
}
for (int z = 2; z <= 4; z += 2) {
for (int y = z; y <= ssq; y += 6) {
for (int x = 1; x <= ssq && (n = 3 * x * x + y * y) < ss; x += 2)
sieve[n] = !sieve[n];
for (int x = y + 1; x <= ssq && (n = 3 * x * x - y * y) < ss; x += 2)
sieve[n] = !sieve[n];
}
}
for (int z = 1; z <= 2; z++) {
for (int y = 3; y <= ssq; y += 6) {
for (int x = z; x <= ssq && (n = 4 * x * x + y * y) < ss; x += 3)
sieve[n] = !sieve[n];
}
}
for (int k = 5; k <= ssq; k++)
if (sieve[k])
for (int n = k * k; n < ss; n += k * k)
sieve[n] = false;
}
/* ----------------------------------
Prime Factorization
---------------------------------- */
map<ll, map<ll, ll>> primeFactorMap;
map<ll, set<ll>> primeFactorSet;
void primeFactorizeInit() {
primeFactorMap.clear();
primeFactorSet.clear();
}
void primeFactorize(ll N) {
if (N < 0 || N > INF_L)
return;
ll Nc = N, Nsq = sqrt(N + 0.1);
for (int k = 2; k <= Nsq; k++) {
ll dt = 0;
while (Nc % k == 0) {
dt++;
Nc /= k;
}
if (dt > 0)
primeFactorMap[N][k] = dt;
if (N % k == 0) {
primeFactorSet[N].insert(k);
primeFactorSet[N].insert(N / k);
}
}
if (Nc != 1)
primeFactorMap[N][Nc] = 1;
primeFactorSet[N].insert(1);
primeFactorSet[N].insert(N);
}
// ----------------------------------------------------------------
void solve() {
string S;
cin >> S;
vector<int> c(26, 0);
rep(i, 4) c[ctoi(S[i])]++;
bool fg = true;
// rep(i, 26) {cout << itocu(i) << c[i] << endl;}
rep(i, 26) {
if (c[i] != 0 && c[i] != 2) {
fg = false;
}
}
cout_ynl(fg);
}
int main() {
std::ifstream in("input.txt");
std::cin.rdbuf(in.rdbuf());
cin.tie(0);
ios::sync_with_stdio(false);
solve();
return 0;
}
| [
"misc.opposites",
"control_flow.branch.if.condition.change"
] | 793,459 | 793,458 | u947236878 | cpp |
p02987 | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
int count = 0;
cin >> s;
unordered_map<int, int> mp;
for (int i = 0; i < 4; i++) {
if (mp.find(s[i]) == mp.end()) {
mp[s[i]] = 1;
count++;
}
}
if (count == 2) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
int count = 0;
cin >> s;
unordered_map<int, int> mp;
for (int i = 0; i < 4; i++) {
if (mp.find(s[i]) == mp.end()) {
mp[s[i]] = 1;
count++;
}
}
if (count == 2) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | [
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 793,462 | 793,463 | u804446596 | cpp |
p02987 | /*
author : nishi5451
created: 11.08.2020 22:04:07
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
int main() {
string s;
cin >> s;
sort(s.begin(), s.end());
if (s[0] == s[1] && s[2] == s[3] && s[2] != s[3])
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
} | /*
author : nishi5451
created: 11.08.2020 22:04:07
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
int main() {
string s;
cin >> s;
sort(s.begin(), s.end());
if (s[0] == s[1] && s[2] == s[3] && s[2] != s[1])
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
}
| [
"literal.number.change",
"variable_access.subscript.index.change",
"control_flow.branch.if.condition.change"
] | 793,470 | 793,471 | u033937898 | cpp |
p02987 | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep1(i, n) for (ll i = 1; i < n; ++i)
#define mrep(i, n) for (ll i = n; i >= 0; --i)
#define all(a) (a).begin(), (a).end()
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define pl pair<ll, ll>
#define inf 1001001001001001000
//#define mod 1000000007
#define mod 998244353
#define pi 3.1415926535
using namespace std;
struct __INIT {
__INIT() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
}
} __init;
int main(void) {
string s;
cin >> s;
vb cs(26, 0);
vl cnts(26, 0);
for (char c : s) {
cs[c - 'A'] = true;
cnts[c - 'A']++;
}
ll s1 = 0, s2 = 0;
rep(i, 26) { s1 += cs[i]; }
if (s1 == 2) {
bool dame = false;
rep(i, 26) {
if (cs[i]) {
cnts[i] != 2;
dame = true;
break;
}
}
if (dame == false) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} else {
cout << "No" << endl;
}
return 0;
}
| #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep1(i, n) for (ll i = 1; i < n; ++i)
#define mrep(i, n) for (ll i = n; i >= 0; --i)
#define all(a) (a).begin(), (a).end()
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define pl pair<ll, ll>
#define inf 1001001001001001000
//#define mod 1000000007
#define mod 998244353
#define pi 3.1415926535
using namespace std;
struct __INIT {
__INIT() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
}
} __init;
int main(void) {
string s;
cin >> s;
vb cs(26, 0);
vl cnts(26, 0);
for (char c : s) {
cs[c - 'A'] = true;
cnts[c - 'A']++;
}
ll s1 = 0, s2 = 0;
rep(i, 26) { s1 += cs[i]; }
if (s1 == 2) {
bool dame = false;
rep(i, 26) {
if (cs[i] && cnts[i] != 2) {
dame = true;
break;
}
}
if (dame == false) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} else {
cout << "No" << endl;
}
return 0;
}
| [
"control_flow.branch.if.condition.change"
] | 793,474 | 793,475 | u386131832 | cpp |
p02987 | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
string ans = "No";
if (s[0] == s[1] || s[2] == s[3] || s[0] != s[2]) {
ans = "Yes";
} else if (s[0] == s[2] || s[1] == s[3] || s[0] != s[1]) {
ans = "Yes";
} else if (s[0] == s[3] || s[1] == s[2] || s[0] != s[1]) {
ans = "Yes";
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
string ans = "No";
if (s[0] == s[1] && s[2] == s[3] && s[0] != s[2]) {
ans = "Yes";
} else if (s[0] == s[2] && s[1] == s[3] && s[0] != s[1]) {
ans = "Yes";
} else if (s[0] == s[3] && s[1] == s[2] && s[0] != s[1]) {
ans = "Yes";
}
cout << ans << endl;
return 0;
} | [
"misc.opposites",
"control_flow.branch.if.condition.change"
] | 793,476 | 793,477 | u221391729 | cpp |
p02987 | #include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set \
tree<int, null_type, less<int>, rb_tree_tag, \
tree_order_statistics_node_update>
#define FS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define ll long long int
#define ld long double
#define pb push_back
#define bp __builtin_popcount
#define sz size()
#define ff first
#define ss second
#define vll vector<ll>
#define vbool vector<bool>
#define vpll vector<pair<ll, ll>>
#define pll pair<ll, ll>
#define vllv vector<vector<ll>>
#define setpri(x) cout << setprecision(x) << fixed;
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define yesr \
{ \
cout << "YES" << endl; \
return; \
}
#define nor \
{ \
cout << "NO" << endl; \
return; \
}
// getline (std::cin,name);
ll MOD = 1e9 + 7;
ll ceil1(ll n, ll x) { return (n - 1) / x + (n > 0); }
ll gcd(ll a, ll b) { return __gcd(a, b); }
ll lcm(ll a, ll b) { return (max(a, b) / gcd(a, b)) * min(a, b); }
ll pow1(ll n, ll m, ll mod = MOD);
ll pow2(ll n, ll k);
ll modinv(ll n, ll mod = MOD) { return pow1(n, mod - 2, mod); }
bool func(pair<ll, ll> &a, pair<ll, ll> &b) {
if (a.ff != b.ff)
return a.ff < b.ff;
return a.ss > b.ss;
}
ll const N = (ll)3e2 + 11;
ll const LG = (ll)log2(N) + 1;
void solve() {
ll i, j, k, l, n, m, x, y, z, r;
string s;
cin >> s;
n = s.sz;
map<char, ll> mp;
for (i = 0; i < n; i++) {
mp[s[i]]++;
}
if (mp.sz != 2 || mp[s[0]] != 2) {
cout << "NO\n";
} else {
cout << "YES\n";
}
}
int main() {
FS;
ll i, j, k, n, m, x, y, z, q;
q = 1;
// cin>>q;
while (q--) {
solve();
}
return 0;
}
ll pow1(ll n, ll m, ll mod) {
if (m == 0)
return 1;
if (m % 2 == 0)
return pow1((n * n) % mod, m / 2, mod);
return (pow1((n * n) % mod, m / 2, mod) * n) % mod;
}
ll pow2(ll n, ll k) {
ll ans = 1;
while (k > 0) {
if (k % 2 == 1)
ans = ans * n;
n = n * n;
k /= 2;
}
return ans;
} | #include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set \
tree<int, null_type, less<int>, rb_tree_tag, \
tree_order_statistics_node_update>
#define FS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define ll long long int
#define ld long double
#define pb push_back
#define bp __builtin_popcount
#define sz size()
#define ff first
#define ss second
#define vll vector<ll>
#define vbool vector<bool>
#define vpll vector<pair<ll, ll>>
#define pll pair<ll, ll>
#define vllv vector<vector<ll>>
#define setpri(x) cout << setprecision(x) << fixed;
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define yesr \
{ \
cout << "YES" << endl; \
return; \
}
#define nor \
{ \
cout << "NO" << endl; \
return; \
}
// getline (std::cin,name);
ll MOD = 1e9 + 7;
ll ceil1(ll n, ll x) { return (n - 1) / x + (n > 0); }
ll gcd(ll a, ll b) { return __gcd(a, b); }
ll lcm(ll a, ll b) { return (max(a, b) / gcd(a, b)) * min(a, b); }
ll pow1(ll n, ll m, ll mod = MOD);
ll pow2(ll n, ll k);
ll modinv(ll n, ll mod = MOD) { return pow1(n, mod - 2, mod); }
bool func(pair<ll, ll> &a, pair<ll, ll> &b) {
if (a.ff != b.ff)
return a.ff < b.ff;
return a.ss > b.ss;
}
ll const N = (ll)3e2 + 11;
ll const LG = (ll)log2(N) + 1;
void solve() {
ll i, j, k, l, n, m, x, y, z, r;
string s;
cin >> s;
n = s.sz;
map<char, ll> mp;
for (i = 0; i < n; i++) {
mp[s[i]]++;
}
if (mp.sz != 2 || mp[s[0]] != 2) {
cout << "No\n";
} else {
cout << "Yes\n";
}
}
int main() {
FS;
ll i, j, k, n, m, x, y, z, q;
q = 1;
// cin>>q;
while (q--) {
solve();
}
return 0;
}
ll pow1(ll n, ll m, ll mod) {
if (m == 0)
return 1;
if (m % 2 == 0)
return pow1((n * n) % mod, m / 2, mod);
return (pow1((n * n) % mod, m / 2, mod) * n) % mod;
}
ll pow2(ll n, ll k) {
ll ans = 1;
while (k > 0) {
if (k % 2 == 1)
ans = ans * n;
n = n * n;
k /= 2;
}
return ans;
} | [
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 793,485 | 793,486 | u293991054 | cpp |
p02987 | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
int main() {
string str;
cin >> str;
set<char> s;
for (int i = 0; i < 4; i++)
s.insert(str[i]);
if (s.size() == 2)
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
int main() {
string str;
cin >> str;
set<char> s;
for (int i = 0; i < 4; i++)
s.insert(str[i]);
if (s.size() == 2)
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
} | [
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 793,487 | 793,488 | u511332668 | cpp |
p02987 | #include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
const int INF32 = 1 << 30;
const ll INF64 = 1LL << 60;
void solve() {
string s;
cin >> s;
sort(s.begin(), s.end());
if (s[0] == s[1] && s[2] == s[3] && s[1] != s[2])
cout << "YES";
else
cout << "NO";
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
solve();
return 0;
} | #include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
const int INF32 = 1 << 30;
const ll INF64 = 1LL << 60;
void solve() {
string s;
cin >> s;
sort(s.begin(), s.end());
if (s[0] == s[1] && s[2] == s[3] && s[1] != s[2])
cout << "Yes";
else
cout << "No";
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
solve();
return 0;
} | [
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 793,500 | 793,501 | u311090179 | cpp |
p02987 | #include <iostream>
using namespace std;
int main() {
int seged = 0;
string S = "ASSA";
cin >> S;
for (int i = 0; i < S.length() - 1; i++) {
for (int j = i + 1; S.length(); j++) {
if (S[i] == S[j]) {
seged += 1;
}
}
}
if (seged == 2) {
cout << "Yes";
} else {
cout << "No";
}
return 0;
}
| #include <iostream>
using namespace std;
int main() {
int seged = 0;
string S = "ASSA";
cin >> S;
for (int i = 0; i < S.length() - 1; i++) {
for (int j = i + 1; j < S.length(); j++) {
if (S[i] == S[j]) {
seged += 1;
}
}
}
if (seged == 2) {
cout << "Yes";
} else {
cout << "No";
}
return 0;
}
| [
"control_flow.loop.for.condition.change"
] | 793,502 | 793,503 | u742481447 | cpp |
p02987 | #include <bits/stdc++.h>
using namespace std;
int main() {
unordered_map<char, int> mp;
string s;
cin >> s;
for (auto x : s) {
mp[x]++;
}
for (auto x : mp) {
if (x.second != 2) {
cout << "NO";
return 0;
}
}
cout << "Yes";
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
unordered_map<char, int> mp;
string s;
cin >> s;
for (auto x : s) {
mp[x]++;
}
for (auto x : mp) {
if (x.second != 2) {
cout << "No";
return 0;
}
}
cout << "Yes";
}
| [
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 793,513 | 793,514 | u180607483 | cpp |
p02987 | #include <bits/stdc++.h>
using namespace std;
int main() {
unordered_map<char, int> mp;
string s;
cin >> s;
for (auto x : s) {
mp[x]++;
}
for (auto x : mp) {
if (x.second != 2) {
cout << "NO";
return 0;
}
}
cout << "YES";
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
unordered_map<char, int> mp;
string s;
cin >> s;
for (auto x : s) {
mp[x]++;
}
for (auto x : mp) {
if (x.second != 2) {
cout << "No";
return 0;
}
}
cout << "Yes";
}
| [
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 793,515 | 793,514 | u180607483 | cpp |
p02987 | #include <bits/stdc++.h>
using namespace std;
int main() {
unordered_map<char, int> mp;
string s;
cin >> s;
for (auto x : s) {
mp[x]++;
}
for (auto x : mp) {
if (x.second != 4) {
cout << "NO";
return 0;
}
}
cout << "YES";
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
unordered_map<char, int> mp;
string s;
cin >> s;
for (auto x : s) {
mp[x]++;
}
for (auto x : mp) {
if (x.second != 2) {
cout << "No";
return 0;
}
}
cout << "Yes";
}
| [
"literal.number.change",
"control_flow.branch.if.condition.change",
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 793,516 | 793,514 | u180607483 | cpp |
p02987 | #include <bits/stdc++.h>
using namespace std;
int main() {
string S;
cin >> S;
int size = S.size();
map<char, int> count;
for (int i = 0; i < size; i++) {
char tmp = S[i];
count[tmp] += 1;
}
bool flag = true;
for (auto p : count) {
auto value = p.second;
if (value != 2) {
flag = false;
break;
}
}
if (flag) {
cout << "Yes" << endl;
} else {
cout << "Np" << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
string S;
cin >> S;
int size = S.size();
map<char, int> count;
for (int i = 0; i < size; i++) {
char tmp = S[i];
count[tmp] += 1;
}
bool flag = true;
for (auto p : count) {
auto value = p.second;
if (value != 2) {
flag = false;
break;
}
}
if (flag) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | [
"literal.string.change",
"io.output.change"
] | 793,517 | 793,518 | u431458875 | cpp |
p02987 | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
map<char, int> mp;
for (int i = 0; i < s.size(); i++) {
mp[s[i]]++;
}
if (mp.size() != 2) {
cout << "NO" << endl;
return 0;
}
for (auto a : mp) {
if (a.second != 2) {
cout << "NO" << endl;
return 0;
}
}
cout << "YES" << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
map<char, int> mp;
for (int i = 0; i < s.size(); i++) {
mp[s[i]]++;
}
if (mp.size() != 2) {
cout << "No" << endl;
return 0;
}
for (auto a : mp) {
if (a.second != 2) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
} | [
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 793,521 | 793,522 | u423327360 | cpp |
p02987 | // Author- VMAX
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_multiset \
tree<long long, null_type, less_equal<long long>, rb_tree_tag, \
tree_order_statistics_node_update>
#define ordered_set \
tree<long long, null_type, less<long long>, rb_tree_tag, \
tree_order_statistics_node_update>
using namespace std;
#define ll long long int
#define YES \
cout << "YES" \
<< "\n";
#define NO \
cout << "NO" \
<< "\n";
#define ld long double
#define yes \
cout << "yes" \
<< "\n";
#define no \
cout << "no" \
<< "\n";
#define No \
cout << "No" \
<< "\n";
#define Yes \
cout << "Yes" \
<< "\n";
#define f(i, a) for (i = 0; i < a; i++)
#define fo(i, a) for (i = 1; i <= a; i++)
#define fa(i, a) for (auto i : a)
#define r(i, a) for (auto i = a.rbegin(); i != a.rend(); i++)
#define en cout << "\n";
#define ull unsigned long long int
#define o(x) cout << x << "\n";
#define o1(x) cout << x << " ";
#define pb push_back
#define F first
#define in insert
#define mp make_pair
#define S second
#define pre(n) cout << fixed << setprecision(n);
#define gcd(a, b) __gcd(a, b)
#define bs binary_search
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define test \
ll t; \
cin >> t; \
while (t-- > 0)
const ll Mod = 998244353;
#define mod 1000000007
#define pi 3.14159265358979323846
#define all(x) x.begin(), x.end()
#define re return 0;
// *#######################################################################################*
/*
bool isp(ll n)
{
ll i;
for(i=2;i*i<=n;i++)
{
if(n%i==0)
{
return false;
}
}
}
*/
ll powerm(ll x, unsigned ll y, ll p) {
ll res = 1;
x = x % p;
if (x == 0)
return 0;
while (y > 0) {
if (y & 1)
res = (res * x) % p;
y = y >> 1; // y = y/2
x = (x * x) % p;
}
return res;
}
long long lcm(long long a, long long b) { //最小公倍数を求める
return a * b / gcd(a, b);
}
// ll ss[2][(1<<22)+10];
int main()
{
fast
string s;
cin >> s;
sort(all(s));
if (s[0] == s[1] && s[2] == s[3] && s[0] != s[2]) {
YES
} else {
NO
}
re
}
| // Author- VMAX
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_multiset \
tree<long long, null_type, less_equal<long long>, rb_tree_tag, \
tree_order_statistics_node_update>
#define ordered_set \
tree<long long, null_type, less<long long>, rb_tree_tag, \
tree_order_statistics_node_update>
using namespace std;
#define ll long long int
#define YES \
cout << "YES" \
<< "\n";
#define NO \
cout << "NO" \
<< "\n";
#define ld long double
#define yes \
cout << "yes" \
<< "\n";
#define no \
cout << "no" \
<< "\n";
#define No \
cout << "No" \
<< "\n";
#define Yes \
cout << "Yes" \
<< "\n";
#define f(i, a) for (i = 0; i < a; i++)
#define fo(i, a) for (i = 1; i <= a; i++)
#define fa(i, a) for (auto i : a)
#define r(i, a) for (auto i = a.rbegin(); i != a.rend(); i++)
#define en cout << "\n";
#define ull unsigned long long int
#define o(x) cout << x << "\n";
#define o1(x) cout << x << " ";
#define pb push_back
#define F first
#define in insert
#define mp make_pair
#define S second
#define pre(n) cout << fixed << setprecision(n);
#define gcd(a, b) __gcd(a, b)
#define bs binary_search
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define test \
ll t; \
cin >> t; \
while (t-- > 0)
const ll Mod = 998244353;
#define mod 1000000007
#define pi 3.14159265358979323846
#define all(x) x.begin(), x.end()
#define re return 0;
// *#######################################################################################*
/*
bool isp(ll n)
{
ll i;
for(i=2;i*i<=n;i++)
{
if(n%i==0)
{
return false;
}
}
}
*/
ll powerm(ll x, unsigned ll y, ll p) {
ll res = 1;
x = x % p;
if (x == 0)
return 0;
while (y > 0) {
if (y & 1)
res = (res * x) % p;
y = y >> 1; // y = y/2
x = (x * x) % p;
}
return res;
}
long long lcm(long long a, long long b) { //最小公倍数を求める
return a * b / gcd(a, b);
}
// ll ss[2][(1<<22)+10];
int main()
{
fast
string s;
cin >> s;
sort(all(s));
if (s[0] == s[1] && s[2] == s[3] && s[0] != s[2]) {
Yes
} else {
No
}
re
}
| [
"identifier.change"
] | 793,534 | 793,535 | u251432619 | cpp |
p02987 | #include <bits/stdc++.h>
using namespace std;
int main() {
int counter = 0;
vector<char> data(4);
for (int i = 0; i < 4; i++) {
cin >> data[i];
}
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (data[i] == data[j]) {
counter++;
}
}
}
if (counter == 8) {
cout << "Yes";
} else {
cout << "No";
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int counter = 0;
vector<char> data(4);
for (int i = 0; i < 4; i++) {
cin >> data[i];
}
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
if (data[i] == data[j]) {
counter++;
}
}
}
if (counter == 8) {
cout << "Yes";
} else {
cout << "No";
}
} | [
"literal.number.change",
"control_flow.loop.for.condition.change",
"expression.off_by_one",
"expression.operation.binary.change"
] | 793,542 | 793,543 | u636279017 | cpp |
p02987 | #include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
char s[10];
cin >> s;
sort(s, s + 4);
if (s[0] == s[1] && s[1] != s[2] && s[2] == s[3])
cout << "YES\n";
else
cout << "NO\n";
} | #include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
char s[10];
cin >> s;
sort(s, s + 4);
if (s[0] == s[1] && s[1] != s[2] && s[2] == s[3])
cout << "Yes\n";
else
cout << "No\n";
} | [
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 793,560 | 793,561 | u205280593 | cpp |
p02987 | #include <bits/stdc++.h>
#define ll long long int
using namespace std;
const ll mod = 1000000007;
const ll inf = LONG_LONG_MAX;
int main() {
string s;
cin >> s;
if (s[0] == s[1] && s[1] != s[2] && s[2] == s[3])
cout << "Yes" << endl;
else if (s[0] == s[2] && s[1] != s[2] && s[2] == s[1])
cout << "Yes" << endl;
else if (s[0] == s[3] && s[1] == s[2] && s[3] == s[1])
cout << "Yes" << endl;
else
cout << "No" << endl;
} | #include <bits/stdc++.h>
#define ll long long int
using namespace std;
const ll mod = 1000000007;
const ll inf = LONG_LONG_MAX;
int main() {
string s;
cin >> s;
if (s[0] == s[1] && s[1] != s[2] && s[2] == s[3])
cout << "Yes" << endl;
else if (s[0] == s[2] && s[1] != s[2] && s[3] == s[1])
cout << "Yes" << endl;
else if (s[0] == s[3] && s[1] == s[2] && s[3] != s[1])
cout << "Yes" << endl;
else
cout << "No" << endl;
} | [
"literal.number.change",
"variable_access.subscript.index.change",
"control_flow.branch.if.condition.change",
"misc.opposites",
"expression.operator.compare.change"
] | 793,570 | 793,569 | u016987091 | cpp |
p02987 | #include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
string S;
cin >> S;
if (S[0] == S[1] && S[2] == S[3] && S[0] != S[2]) {
cout << "Yes" << endl;
} else if (S[0] == S[2] && S[1] == S[3] && S[0] != S[1]) {
cout << "Yes" << endl;
} else if (S[0] == S[3] && S[1] == S[2] && S[0] == S[1]) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | #include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
string S;
cin >> S;
if (S[0] == S[1] && S[2] == S[3] && S[0] != S[2]) {
cout << "Yes" << endl;
} else if (S[0] == S[2] && S[1] == S[3] && S[0] != S[1]) {
cout << "Yes" << endl;
} else if (S[0] == S[3] && S[1] == S[2] && S[0] != S[1]) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | [
"misc.opposites",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 793,573 | 793,574 | u838276016 | cpp |
p02987 | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
if (s[0] == s[1]) {
if (s[2] == s[3] && s[2] != s[1]) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
} else {
vector<char> a(2);
vector<char> b(2);
a[0] = s[0];
a[1] = s[1];
b[0] = s[2];
b[1] = s[3];
sort(a.begin(), a.end());
sort(b.begin(), b.end());
if (a == b) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
if (s[0] == s[1]) {
if (s[2] == s[3] && s[2] != s[1]) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} else {
vector<char> a(2);
vector<char> b(2);
a[0] = s[0];
a[1] = s[1];
b[0] = s[2];
b[1] = s[3];
sort(a.begin(), a.end());
sort(b.begin(), b.end());
if (a == b) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
} | [
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 793,575 | 793,576 | u518948335 | cpp |
p02987 | #include <bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;
int table[26];
char S[5];
int main() {
for (int i = 0; i < 26; i++) {
table[i] = 0;
}
scanf("%s", S);
for (int i = 0; S[i] != '\0'; i++) {
table[S[i] - 'a']++;
}
int num_2 = 0;
for (int i = 0; i < 26; i++) {
if (table[i] == 2) {
num_2++;
}
}
if (num_2 == 2) {
printf("Yes\n");
} else {
printf("No\n");
}
return 0;
}
| #include <bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;
int table[26];
char S[5];
int main() {
for (int i = 0; i < 26; i++) {
table[i] = 0;
}
scanf("%s", S);
for (int i = 0; S[i] != '\0'; i++) {
table[S[i] - 'A']++;
}
int num_2 = 0;
for (int i = 0; i < 26; i++) {
if (table[i] == 2) {
num_2++;
}
}
if (num_2 == 2) {
printf("Yes\n");
} else {
printf("No\n");
}
return 0;
}
| [
"literal.string.change",
"literal.string.case.change",
"variable_access.subscript.index.change",
"expression.operation.binary.change"
] | 793,597 | 793,598 | u000022466 | cpp |
p02987 | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef tree<ii, null_type, less<ii>, rb_tree_tag,
tree_order_statistics_node_update>
indexed_set;
int main() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
string s;
cin >> s;
map<char, int> ct;
int mx = 0;
for (const char ch : s)
ct[ch]++, mx = max(mx, ct[ch]);
cout << (ct.size() == 2, mx == 2 ? "Yes" : "No") << endl;
return 0;
}
| #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef tree<ii, null_type, less<ii>, rb_tree_tag,
tree_order_statistics_node_update>
indexed_set;
int main() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
string s;
cin >> s;
map<char, int> ct;
int mx = 0;
for (const char ch : s)
ct[ch]++, mx = max(mx, ct[ch]);
cout << (ct.size() == 2 && mx == 2 ? "Yes" : "No") << endl;
return 0;
}
| [
"io.output.change"
] | 793,609 | 793,610 | u912401725 | cpp |
p02987 | #include <bits/stdc++.h>
using namespace std;
int main() {
string S;
cin >> S;
if (S[0] == S[1] && S[2] == S[3] && S[0] != S[2]) {
cout << "Yes" << endl;
}
if (S[0] == S[2] && S[1] == S[3] && S[0] != S[1]) {
cout << "Yes" << endl;
}
if (S[0] == S[3] && S[1] == S[2] && S[0] != S[1]) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
string S;
cin >> S;
if (S[0] == S[1] && S[2] == S[3] && S[0] != S[2]) {
cout << "Yes" << endl;
} else if (S[0] == S[2] && S[1] == S[3] && S[0] != S[1]) {
cout << "Yes" << endl;
} else if (S[0] == S[3] && S[1] == S[2] && S[0] != S[1]) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | [
"control_flow.branch.else_if.replace.add",
"control_flow.branch.if.replace.remove"
] | 793,617 | 793,618 | u484265463 | cpp |
p02987 | #include <bits/stdc++.h>
using namespace std;
int main() {
string S;
if (S[0] == S[1] && S[2] == S[3] && S[0] != S[2]) {
cout << "Yes" << endl;
} else if (S[0] == S[2] && S[1] == S[3] && S[0] != S[1]) {
cout << "Yes" << endl;
} else if (S[0] == S[3] && S[1] == S[2] && S[0] != S[1]) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
string S;
cin >> S;
if (S[0] == S[1] && S[2] == S[3] && S[0] != S[2]) {
cout << "Yes" << endl;
} else if (S[0] == S[2] && S[1] == S[3] && S[0] != S[1]) {
cout << "Yes" << endl;
} else if (S[0] == S[3] && S[1] == S[2] && S[0] != S[1]) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | [] | 793,619 | 793,618 | u484265463 | cpp |
p02987 | #include <bits/stdc++.h>
using namespace std;
int main() {
string S;
if (S[0] == S[1] && S[2] == S[3] && S[0] != S[2]) {
cout << "Yes" << endl;
} else if (S[0] == S[2] && S[1] == S[3] && S[0] != S[1]) {
cout << "Yes" << endl;
} else if (S[0] == S[3] && S[1] == S[2] && S[0] != S[1]) {
cout << "Yes" << endl;
} else {
cout << "NO" << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
string S;
cin >> S;
if (S[0] == S[1] && S[2] == S[3] && S[0] != S[2]) {
cout << "Yes" << endl;
} else if (S[0] == S[2] && S[1] == S[3] && S[0] != S[1]) {
cout << "Yes" << endl;
} else if (S[0] == S[3] && S[1] == S[2] && S[0] != S[1]) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | [
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 793,620 | 793,618 | u484265463 | cpp |
p02987 | #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define endl "\n"
#define all(x) x.begin(), x.end()
#define ll long long
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
string s;
cin >> s;
set<char> se;
for (int i = 0; i < s.size(); i++) {
se.insert(s[i]);
}
if (se.size() != s.size()) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
| #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define endl "\n"
#define all(x) x.begin(), x.end()
#define ll long long
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
string s;
cin >> s;
set<char> se;
for (int i = 0; i < s.size(); i++) {
se.insert(s[i]);
}
if (se.size() == 2) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
| [
"call.remove"
] | 793,621 | 793,622 | u249899006 | cpp |
p02987 | #include <algorithm>
#include <fstream>
#include <iostream>
#include <math.h>
#include <numeric>
#include <stdio.h>
#include <vector>
using namespace std;
int main() {
string s;
cin >> s;
if (s[0] == s[1] && s[1] != s[2] && s[2] == s[3]) {
cout << "Yes" << endl;
}
if (s[0] == s[2] && s[1] != s[2] && s[1] == s[3]) {
cout << "Yes" << endl;
}
if (s[0] == s[3] && s[0] != s[1] && s[1] == s[2]) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
| #include <algorithm>
#include <fstream>
#include <iostream>
#include <math.h>
#include <numeric>
#include <stdio.h>
#include <vector>
using namespace std;
int main() {
string s;
cin >> s;
if (s[0] == s[1] && s[1] != s[2] && s[2] == s[3]) {
cout << "Yes" << endl;
}
else if (s[0] == s[2] && s[1] != s[2] && s[1] == s[3]) {
cout << "Yes" << endl;
}
else if (s[0] == s[3] && s[0] != s[1] && s[1] == s[2]) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
| [
"control_flow.branch.else_if.replace.add",
"control_flow.branch.if.replace.remove"
] | 793,627 | 793,628 | u549383771 | cpp |
p02987 | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
if (s[0] == s[1] && s[1] != s[2] && s[2] == s[3]) {
cout << "Yes" << endl;
}
if (s[0] == s[2] && s[2] != s[1] && s[1] == s[3]) {
cout << "Yes" << endl;
}
if (s[0] == s[3] && s[3] != s[1] && s[1] == s[2]) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
if (s[0] == s[1] && s[1] != s[2] && s[2] == s[3]) {
cout << "Yes" << endl;
} else if (s[0] == s[2] && s[2] != s[1] && s[1] == s[3]) {
cout << "Yes" << endl;
} else if (s[0] == s[3] && s[3] != s[1] && s[1] == s[2]) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | [
"control_flow.branch.else_if.replace.add",
"control_flow.branch.if.replace.remove"
] | 793,647 | 793,648 | u940079168 | cpp |
p02987 |
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
#define ll long long int
int main(void) {
int a, b, d, g, count = 0;
string S, T, U;
map<char, int> mp;
for (int i = 0; i < 4; i++) {
char S;
std::cin >> mp[S];
mp[S]++;
}
if (mp.size() != 2) {
cout << "No" << endl;
return 0;
} else {
for (auto itr = mp.begin(); itr != mp.end(); itr++) {
if (itr->second != 2) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
}
} |
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
#define ll long long int
int main(void) {
int a, b, d, g, count = 0;
string S, T, U;
map<char, int> mp;
for (int i = 0; i < 4; i++) {
char S;
std::cin >> S;
mp[S]++;
}
if (mp.size() != 2) {
cout << "No" << endl;
return 0;
} else {
for (auto itr = mp.begin(); itr != mp.end(); itr++) {
if (itr->second != 2) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
}
} | [] | 793,649 | 793,650 | u829243466 | cpp |
p02987 | #include <bits/stdc++.h>
#define lint long long
lint MOD = 1000000007;
using namespace std;
int main() {
string S;
cin >> S;
bool flag = false;
flag = ((S[0] == S[1] && S[2] == S[3]) || (S[0] == S[2] && S[1] == S[3]) ||
(S[0] == S[3] || S[1] == S[2]));
if (flag) {
if (S[0] == S[1] && S[0] == S[2])
flag = false;
}
if (flag) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | #include <bits/stdc++.h>
#define lint long long
lint MOD = 1000000007;
using namespace std;
int main() {
string S;
cin >> S;
bool flag = false;
flag = ((S[0] == S[1] && S[2] == S[3]) || (S[0] == S[2] && S[1] == S[3]) ||
(S[0] == S[3] && S[1] == S[2]));
if (flag) {
if (S[0] == S[1] && S[0] == S[2])
flag = false;
}
if (flag) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | [
"misc.opposites",
"assignment.value.change",
"expression.operation.binary.change"
] | 793,653 | 793,654 | u432456012 | cpp |
p02987 | #include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int mex = 5001;
#define ll long long
#define test \
int t; \
cin >> t; \
while (t--)
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define fo(i, a, n) for (int i = a; i < n; i++)
#define rfo(i, a, b) for (int i = a; i >= b; i--)
#define bg begin()
#define en end()
#define fi first
#define se second
#define ub upper_bound
#define lb lower_bound
#define pb push_back
#define veci vector<int>
#define veclli vector<long long int>
#define all(x) x.begin(), x.end()
#define sci(x) scanf("%d", &x);
#define scc(x) scanf("%c", &x);
#define scs(x) scanf("%s", x);
#define debug(arr, n) \
for (int i = 0; i < n; i++) \
printf("%d ", arr[i]);
#define sz(x) x.size()
#define loop(x) for (auto it = x.begin(); it != x.end(); it++)
int main() {
string s;
cin >> s;
map<char, int> mp;
fo(i, 0, sz(s)) mp[s[i]]++;
int fg = 0;
if (sz(mp) == 2) {
loop(mp) if (it->se != 2) fg = 1;
} else
fg = 1;
if (fg)
cout << "NO" << endl;
else
cout << "YES" << endl;
} | #include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int mex = 5001;
#define ll long long
#define test \
int t; \
cin >> t; \
while (t--)
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define fo(i, a, n) for (int i = a; i < n; i++)
#define rfo(i, a, b) for (int i = a; i >= b; i--)
#define bg begin()
#define en end()
#define fi first
#define se second
#define ub upper_bound
#define lb lower_bound
#define pb push_back
#define veci vector<int>
#define veclli vector<long long int>
#define all(x) x.begin(), x.end()
#define sci(x) scanf("%d", &x);
#define scc(x) scanf("%c", &x);
#define scs(x) scanf("%s", x);
#define debug(arr, n) \
for (int i = 0; i < n; i++) \
printf("%d ", arr[i]);
#define sz(x) x.size()
#define loop(x) for (auto it = x.begin(); it != x.end(); it++)
int main() {
string s;
cin >> s;
map<char, int> mp;
fo(i, 0, sz(s)) mp[s[i]]++;
int fg = 0;
if (sz(mp) == 2) {
loop(mp) if (it->se != 2) fg = 1;
} else
fg = 1;
if (fg)
cout << "No" << endl;
else
cout << "Yes" << endl;
} | [
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 793,657 | 793,658 | u468743462 | cpp |
p02987 | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int t = 0;
if (s.at(0) = s.at(1)) {
t++;
}
if (s.at(0) = s.at(2)) {
t++;
}
if (s.at(0) = s.at(3)) {
t++;
}
if (s.at(1) = s.at(2)) {
t++;
}
if (s.at(1) = s.at(3)) {
t++;
}
if (s.at(2) = s.at(3)) {
t++;
}
if (t == 2) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int t = 0;
if (s.at(0) == s.at(1)) {
t++;
}
if (s.at(0) == s.at(2)) {
t++;
}
if (s.at(0) == s.at(3)) {
t++;
}
if (s.at(1) == s.at(2)) {
t++;
}
if (s.at(1) == s.at(3)) {
t++;
}
if (s.at(2) == s.at(3)) {
t++;
}
if (t == 2) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
| [
"expression.operation.compare.replace.add",
"assignment.replace.remove",
"misc.typo"
] | 793,663 | 793,664 | u210234656 | cpp |
p02987 | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define rep(a, n) for (int i = a; i < n; i++)
#define rep1(a, n) for (int i = a; i <= n; i++)
int main() {
string s;
cin >> s;
sort(s.begin(), s.end());
cout << s;
if (s[0] == s[1] && s[2] == s[3] && s[0] != s[2])
cout << "Yes\n";
else
cout << "No\n";
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define rep(a, n) for (int i = a; i < n; i++)
#define rep1(a, n) for (int i = a; i <= n; i++)
int main() {
string s;
cin >> s;
sort(s.begin(), s.end());
if (s[0] == s[1] && s[2] == s[3] && s[0] != s[2])
cout << "Yes\n";
else
cout << "No\n";
return 0;
}
| [] | 793,675 | 793,676 | u507549471 | cpp |
p02987 | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
if (s.at(0) == s.at(1) && s.at(1) != s.at(2) && s.at(1) != s.at(3)) {
cout << "Yes" << endl;
} else if (s.at(0) == s.at(2) && s.at(2) != s.at(1) && s.at(2) != s.at(3)) {
cout << "Yes" << endl;
} else if (s.at(0) == s.at(3) && s.at(3) != s.at(1) && s.at(3) != s.at(2)) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
if (s.at(0) == s.at(1) && s.at(1) != s.at(2) && s.at(2) == s.at(3)) {
cout << "Yes" << endl;
} else if (s.at(0) == s.at(2) && s.at(2) != s.at(1) && s.at(1) == s.at(3)) {
cout << "Yes" << endl;
} else if (s.at(0) == s.at(3) && s.at(3) != s.at(1) && s.at(1) == s.at(2)) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | [
"literal.number.change",
"control_flow.branch.if.condition.change",
"misc.opposites",
"expression.operator.compare.change"
] | 793,679 | 793,680 | u637451088 | cpp |
p02987 | #include <bits/stdc++.h>
using namespace std;
int main() {
string S;
for (int i = 0; i < 4; i++) {
cin >> S[i];
}
sort(S.begin(), S.begin() + 4);
int cont = 1;
for (int i = 0; i < 3; i++) {
if (S[i] != S[i + 1]) {
cont++;
}
}
if (cont == 2) {
if (S[1] != S[2]) {
cout << "YES";
return 0;
}
}
cout << "NO";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
string S;
for (int i = 0; i < 4; i++) {
cin >> S[i];
}
sort(S.begin(), S.begin() + 4);
int cont = 1;
for (int i = 0; i < 3; i++) {
if (S[i] != S[i + 1]) {
cont++;
}
}
if (cont == 2) {
if (S[1] != S[2]) {
cout << "Yes";
return 0;
}
}
cout << "No";
return 0;
} | [
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 793,683 | 793,684 | u721120486 | cpp |
p02987 | #include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
int main() {
int i, j, k;
string s;
cin >> s;
int cnt = 0;
char a = s[0];
char b = s[1];
char c = s[2];
char d = s[3];
if (a == b)
cnt++;
if (a == c)
cnt++;
if (a == d)
cnt++;
if (b == c)
cnt++;
if (b == d)
cnt++;
if (d == d)
cnt++;
if (cnt == 2)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
| #include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
int main() {
int i, j, k;
string s;
cin >> s;
int cnt = 0;
char a = s[0];
char b = s[1];
char c = s[2];
char d = s[3];
if (a == b)
cnt++;
if (a == c)
cnt++;
if (a == d)
cnt++;
if (b == c)
cnt++;
if (b == d)
cnt++;
if (c == d)
cnt++;
if (cnt == 2)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
| [
"identifier.change",
"control_flow.branch.if.condition.change"
] | 793,687 | 793,688 | u765690804 | cpp |
p02987 | #include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
typedef long long ll;
#define all(x) (x).begin(), (x).end() // sortなどの引数を省略
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define max3(x, y, z) max(x, max(y, z))
#ifdef _MSC_FULL_VER //デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
if (false) \
cout
#define debug() if (false)
#define check(x) \
if (false) \
cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
if (false) \
cout << "☆" << x << endl
#endif
using namespace std;
int main() {
string a;
cin >> a;
if (a[0] == a[1] and a[2] == a[3] and a[0] != a[2]) {
cout << "Yes";
} else if (a[0] == a[2] and a[1] == a[3] and a[0] != a[1]) {
cout << "Yes";
} else if (a[0] == a[3] and a[1] == a[2] and a[0] == a[1]) {
cout << "Yes";
} else {
cout << "No";
}
}
/*
//よく使うやつ
int N;
cin >> N;
vector<int> list(N);
for (int i = 0; i < N; i++) {
cin >> list[i];
}
// for文
for (int i = 0; i < N; i++) {
}
//配列
vector<int> vec;
vec.at(i)
vector<vector<int>> vec(10, vector<int>(10));
sort(all(vec));
sort(all(vec), greater<int>());
//配列の内容表示
dout << "====vecの内容====\n";
for (int i = 0; i < N; i++) dout << vec[i] << endl;
dout << "====ここまで====\n";
*/
| #include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
typedef long long ll;
#define all(x) (x).begin(), (x).end() // sortなどの引数を省略
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define max3(x, y, z) max(x, max(y, z))
#ifdef _MSC_FULL_VER //デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
if (false) \
cout
#define debug() if (false)
#define check(x) \
if (false) \
cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
if (false) \
cout << "☆" << x << endl
#endif
using namespace std;
int main() {
string a;
cin >> a;
if (a[0] == a[1] and a[2] == a[3] and a[0] != a[2]) {
cout << "Yes";
} else if (a[0] == a[2] and a[1] == a[3] and a[0] != a[1]) {
cout << "Yes";
} else if (a[0] == a[3] and a[1] == a[2] and a[0] != a[1]) {
cout << "Yes";
} else {
cout << "No";
}
}
/*
//よく使うやつ
int N;
cin >> N;
vector<int> list(N);
for (int i = 0; i < N; i++) {
cin >> list[i];
}
// for文
for (int i = 0; i < N; i++) {
}
//配列
vector<int> vec;
vec.at(i)
vector<vector<int>> vec(10, vector<int>(10));
sort(all(vec));
sort(all(vec), greater<int>());
//配列の内容表示
dout << "====vecの内容====\n";
for (int i = 0; i < N; i++) dout << vec[i] << endl;
dout << "====ここまで====\n";
*/
| [
"misc.opposites",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 793,691 | 793,692 | u043964516 | cpp |
p02987 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string s;
cin >> s;
sort(s.begin(), s.end());
if (s[0] == s[1] && s[2] == s[3] && s[1] != s[2]) {
cout << "YES\n";
} else {
cout << "NO\n";
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string s;
cin >> s;
sort(s.begin(), s.end());
if (s[0] == s[1] && s[2] == s[3] && s[1] != s[2]) {
cout << "Yes\n";
} else {
cout << "No\n";
}
return 0;
}
| [
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 793,704 | 793,705 | u790977255 | cpp |
p02987 | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
if ((s[0] == s[1] && s[2] == s[3]) && s[0] != s[2])
cout << "Yes" << endl;
else if ((s[0] == s[2] && s[1] == s[3]) && s[0] != s[1])
cout << "Yes" << endl;
if ((s[0] == s[3] && s[1] == s[2]) && s[0] != s[2])
cout << "Yes" << endl;
else
cout << "No" << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
if ((s[0] == s[1] && s[2] == s[3]) && s[0] != s[2])
cout << "Yes" << endl;
else if ((s[0] == s[2] && s[1] == s[3]) && s[0] != s[1])
cout << "Yes" << endl;
else if ((s[0] == s[3] && s[1] == s[2]) && s[0] != s[2])
cout << "Yes" << endl;
else
cout << "No" << endl;
}
| [
"control_flow.branch.else_if.replace.add",
"control_flow.branch.if.replace.remove"
] | 793,706 | 793,707 | u105533331 | cpp |
p02987 | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
int main() {
string s;
bool ans = false;
if (s[0] == s[1] && s[2] == s[3] && s[1] != s[3])
ans = true;
if (s[0] == s[2] && s[1] == s[3] && s[0] != s[1])
ans = true;
if (s[0] == s[3] && s[1] == s[2] && s[0] != s[1])
ans = true;
cout << (ans ? "Yes" : "No");
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
int main() {
string s;
cin >> s;
bool ans = false;
if (s[0] == s[1] && s[2] == s[3] && s[1] != s[3])
ans = true;
if (s[0] == s[2] && s[1] == s[3] && s[0] != s[1])
ans = true;
if (s[0] == s[3] && s[1] == s[2] && s[0] != s[1])
ans = true;
cout << (ans ? "Yes" : "No");
return 0;
} | [] | 793,708 | 793,709 | u548977290 | cpp |
p02987 | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
int main() {
string s;
cin >> s;
bool flag = false;
if (s[0] == s[1] && s[0] != s[2] && s[0] != s[3])
flag = true;
if (s[0] == s[2] && s[0] != s[1] && s[0] != s[3])
flag = true;
if (s[0] == s[3] && s[0] != s[1] && s[0] != s[2])
flag = true;
if (flag)
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
int main() {
string s;
cin >> s;
bool flag = false;
if (s[0] == s[1] && s[0] != s[2] && s[2] == s[3])
flag = true;
if (s[0] == s[2] && s[0] != s[1] && s[1] == s[3])
flag = true;
if (s[0] == s[3] && s[0] != s[1] && s[1] == s[2])
flag = true;
if (flag)
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
} | [
"literal.number.change",
"variable_access.subscript.index.change",
"control_flow.branch.if.condition.change",
"misc.opposites",
"expression.operator.compare.change"
] | 793,710 | 793,711 | u823722490 | cpp |
p02987 | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
if (s[0] == s[1] && s[2] == s[3] && s[0] != s[2])
cout << "Yes";
if (s[0] == s[2] && s[1] == s[3] && s[0] != s[1])
cout << "Yes";
if (s[0] == s[3] && s[1] == s[2] && s[0] != s[1])
cout << "Yes";
else
cout << "No";
} | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
if (s[0] == s[1] && s[2] == s[3] && s[0] != s[2])
cout << "Yes";
else if (s[0] == s[2] && s[1] == s[3] && s[0] != s[1])
cout << "Yes";
else if (s[0] == s[3] && s[1] == s[2] && s[0] != s[1])
cout << "Yes";
else
cout << "No";
} | [
"control_flow.branch.else_if.replace.add",
"control_flow.branch.if.replace.remove"
] | 793,716 | 793,717 | u411916435 | cpp |
p02987 | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
if (s.at(0) == s.at(1) && s.at(2) == s.at(3) && s.at(0) == s.at(2))
cout << "Yes" << endl;
else if (s.at(0) == s.at(2) && s.at(1) == s.at(3) && s.at(0) == s.at(3))
cout << "Yes" << endl;
else if (s.at(0) == s.at(3) && s.at(1) == s.at(2) && s.at(0) == s.at(1))
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
if (s.at(0) == s.at(1) && s.at(2) == s.at(3) && s.at(0) != s.at(2))
cout << "Yes" << endl;
else if (s.at(0) == s.at(2) && s.at(1) == s.at(3) && s.at(0) != s.at(3))
cout << "Yes" << endl;
else if (s.at(0) == s.at(3) && s.at(1) == s.at(2) && s.at(0) != s.at(1))
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
} | [
"misc.opposites",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 793,718 | 793,719 | u808743599 | cpp |
p02987 | #include <bits/stdc++.h>
using namespace std;
int main() {
string S;
cin >> S;
if (S.at(0) == S.at(1)) {
if (S.at(2) == S.at(3) && S.at(0) != S.at(2))
cout << "Yes" << endl;
else
cout << "No" << endl;
}
if (S.at(0) == S.at(2)) {
if (S.at(1) == S.at(3) && S.at(0) != S.at(1))
cout << "Yes" << endl;
else
cout << "No" << endl;
}
if (S.at(0) == S.at(3)) {
if (S.at(1) == S.at(2) && S.at(0) != S.at(1))
cout << "Yes" << endl;
else
cout << "No" << endl;
} else
cout << "No" << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
string S;
cin >> S;
if (S.at(0) == S.at(1)) {
if (S.at(2) == S.at(3) && S.at(0) != S.at(2))
cout << "Yes" << endl;
else
cout << "No" << endl;
} else if (S.at(0) == S.at(2)) {
if (S.at(1) == S.at(3) && S.at(0) != S.at(1))
cout << "Yes" << endl;
else
cout << "No" << endl;
} else if (S.at(0) == S.at(3)) {
if (S.at(1) == S.at(2) && S.at(0) != S.at(1))
cout << "Yes" << endl;
else
cout << "No" << endl;
} else
cout << "No" << endl;
}
| [
"control_flow.branch.else_if.replace.add",
"control_flow.branch.if.replace.remove"
] | 793,724 | 793,725 | u433189059 | cpp |
p02987 | #include <bits/stdc++.h>
using namespace std;
int main() {
string S;
cin >> S;
if (S.at(0) == S.at(1)) {
if (S.at(2) == S.at(3) || S.at(0) != S.at(2))
cout << "Yes" << endl;
else
cout << "No" << endl;
}
if (S.at(0) == S.at(2)) {
if (S.at(1) == S.at(3) || S.at(0) != S.at(1))
cout << "Yes" << endl;
else
cout << "No" << endl;
}
if (S.at(0) == S.at(3)) {
if (S.at(1) == S.at(2) || S.at(0) != S.at(1))
cout << "Yes" << endl;
else
cout << "No" << endl;
} else
cout << "No" << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
string S;
cin >> S;
if (S.at(0) == S.at(1)) {
if (S.at(2) == S.at(3) && S.at(0) != S.at(2))
cout << "Yes" << endl;
else
cout << "No" << endl;
} else if (S.at(0) == S.at(2)) {
if (S.at(1) == S.at(3) && S.at(0) != S.at(1))
cout << "Yes" << endl;
else
cout << "No" << endl;
} else if (S.at(0) == S.at(3)) {
if (S.at(1) == S.at(2) && S.at(0) != S.at(1))
cout << "Yes" << endl;
else
cout << "No" << endl;
} else
cout << "No" << endl;
}
| [
"misc.opposites",
"control_flow.branch.if.condition.change",
"control_flow.branch.else_if.replace.add",
"control_flow.branch.if.replace.remove"
] | 793,726 | 793,725 | u433189059 | cpp |
p02987 | #include <iostream>
#include <stdio.h>
//#include <bits/stdc++.h>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cmath>
#include <cstdint>
#include <cstring>
#include <float.h>
#include <iomanip>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#define INF 1e7
#define rep(i, n) for (int i = 0; (i) < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); (i) <= (int)(b); i++)
#define VEC(type, c, n) \
std::vector<type> c(n); \
for (auto &i : c) \
std::cin >> i;
#define vec(type, n) vector<type>(n)
#define vvec(m, n) vector<vector<int>>(int(m), vector<int>(n))
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int, int>;
int main() {
string s;
map<char, int> mp;
rep(i, s.size()) { mp[s[i]]++; }
for (auto m : mp) {
if (m.second != 2) {
cout << "No";
return 0;
}
}
cout << "Yes";
}
| #include <iostream>
#include <stdio.h>
//#include <bits/stdc++.h>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cmath>
#include <cstdint>
#include <cstring>
#include <float.h>
#include <iomanip>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#define INF 1e7
#define rep(i, n) for (int i = 0; (i) < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); (i) <= (int)(b); i++)
#define VEC(type, c, n) \
std::vector<type> c(n); \
for (auto &i : c) \
std::cin >> i;
#define vec(type, n) vector<type>(n)
#define vvec(m, n) vector<vector<int>>(int(m), vector<int>(n))
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int, int>;
int main() {
string s;
cin >> s;
map<char, int> mp;
rep(i, s.size()) { mp[s[i]]++; }
for (auto m : mp) {
if (m.second != 2) {
cout << "No";
return 0;
}
}
cout << "Yes";
}
| [] | 793,727 | 793,728 | u516525290 | cpp |
p02987 | #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
int main() {
string str;
cin >> str;
vector<char> vec(4);
for (int i = 0; i < 4; i++) {
vec.at(i) = str.at(i);
}
sort(vec.begin(), vec.end());
if (vec.at(0) == vec.at(1) && vec.at(2) == vec.at(3) &&
vec.at(0) == vec.at(3)) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
| #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
int main() {
string str;
cin >> str;
vector<char> vec(4);
for (int i = 0; i < 4; i++) {
vec.at(i) = str.at(i);
}
sort(vec.begin(), vec.end());
if (vec.at(0) == vec.at(1) && vec.at(2) == vec.at(3) &&
vec.at(0) != vec.at(3)) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
| [
"misc.opposites",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 793,729 | 793,730 | u263000123 | cpp |
p02987 | // _/ _/ _/_/_/ _/
//_/_/_/_/ _/_/ _/_/_/_/ _/_/ _/ _/_/
// _/ _/ _/ _/ _/ _/ _/_/_/ _/
//_/ _/ _/ _/ _/ _/ _/ _/ _/
// _/_/ _/_/ _/_/ _/_/ _/_/ _/
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const double pi = 3.14159265358979323846;
const int inf = 2e9;
const ll INF = 9e18;
typedef pair<int, int> P;
int main() {
cin.tie(0), cout.tie(0);
ios::sync_with_stdio(false);
string s;
cin >> s;
set<char> se;
for (int i = 0; i < 4; i++) {
se.insert(s[i]);
}
sort(s.begin(), s.end());
if (se.size() == 2 && s[0] == s[2]) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
| // _/ _/ _/_/_/ _/
//_/_/_/_/ _/_/ _/_/_/_/ _/_/ _/ _/_/
// _/ _/ _/ _/ _/ _/ _/_/_/ _/
//_/ _/ _/ _/ _/ _/ _/ _/ _/
// _/_/ _/_/ _/_/ _/_/ _/_/ _/
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const double pi = 3.14159265358979323846;
const int inf = 2e9;
const ll INF = 9e18;
typedef pair<int, int> P;
int main() {
cin.tie(0), cout.tie(0);
ios::sync_with_stdio(false);
string s;
cin >> s;
set<char> se;
for (int i = 0; i < 4; i++) {
se.insert(s[i]);
}
sort(s.begin(), s.end());
if (se.size() == 2 && s[0] != s[2]) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | [
"misc.opposites",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 793,739 | 793,740 | u401900157 | cpp |
p02987 | // _/ _/ _/_/_/ _/
//_/_/_/_/ _/_/ _/_/_/_/ _/_/ _/ _/_/
// _/ _/ _/ _/ _/ _/ _/_/_/ _/
//_/ _/ _/ _/ _/ _/ _/ _/ _/
// _/_/ _/_/ _/_/ _/_/ _/_/ _/
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const double pi = 3.14159265358979323846;
const int inf = 2e9;
const ll INF = 9e18;
typedef pair<int, int> P;
int main() {
cin.tie(0), cout.tie(0);
ios::sync_with_stdio(false);
string s;
cin >> s;
set<char> se;
for (int i = 0; i < 4; i++) {
se.insert(s[i]);
}
sort(s.begin(), s.end());
if (s.size() == 2 && s[0] == s[2]) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | // _/ _/ _/_/_/ _/
//_/_/_/_/ _/_/ _/_/_/_/ _/_/ _/ _/_/
// _/ _/ _/ _/ _/ _/ _/_/_/ _/
//_/ _/ _/ _/ _/ _/ _/ _/ _/
// _/_/ _/_/ _/_/ _/_/ _/_/ _/
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const double pi = 3.14159265358979323846;
const int inf = 2e9;
const ll INF = 9e18;
typedef pair<int, int> P;
int main() {
cin.tie(0), cout.tie(0);
ios::sync_with_stdio(false);
string s;
cin >> s;
set<char> se;
for (int i = 0; i < 4; i++) {
se.insert(s[i]);
}
sort(s.begin(), s.end());
if (se.size() == 2 && s[0] != s[2]) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | [
"identifier.change",
"control_flow.branch.if.condition.change",
"misc.opposites",
"expression.operator.compare.change"
] | 793,741 | 793,740 | u401900157 | cpp |
p02987 | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
//テストケースはあんまり見ないほうが良い。デバッグする能力が必要.
int main() {
char s[4];
map<char, int> mp;
cin >> s;
rep(i, 4) { ++mp[s[i]]; }
int ans;
for (auto ele : mp) {
if (ele.second == 2) {
++ans;
}
}
if (ans == 2) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
//テストケースはあんまり見ないほうが良い。デバッグする能力が必要.
int main() {
char s[4];
map<char, int> mp;
cin >> s;
rep(i, 4) { ++mp[s[i]]; }
int ans = 0;
for (auto ele : mp) {
if (ele.second == 2) {
++ans;
}
}
if (ans == 2) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
} | [
"variable_declaration.value.change"
] | 793,744 | 793,745 | u412659798 | cpp |
p02987 | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, n) for (int i = 1; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
int main() {
string S;
cin >> S;
if (S[0] == S[1] && S[2] == S[3] && S[0] != S[2])
cout << "Yes";
else if (S[0] == S[2] && S[1] == S[3] && S[0] != S[1])
cout << "Yes";
else if (S[0] == S[3] && S[1] == S[2] && S[0] != S[3])
cout << "Yes";
else
cout << "No";
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, n) for (int i = 1; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
int main() {
string S;
cin >> S;
if (S[0] == S[1] && S[2] == S[3] && S[0] != S[2])
cout << "Yes";
else if (S[0] == S[2] && S[1] == S[3] && S[0] != S[1])
cout << "Yes";
else if (S[0] == S[3] && S[1] == S[2] && S[0] != S[1])
cout << "Yes";
else
cout << "No";
} | [
"literal.number.change",
"variable_access.subscript.index.change",
"control_flow.branch.if.condition.change"
] | 793,746 | 793,747 | u467480147 | cpp |
p02987 | #include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/detail/standard_policies.hpp>
// using namespace __gnu_pbds;
using namespace std;
// template <typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
// tree_order_statistics_node_update>;
typedef long long int ll;
const ll N = 1e5 + 9;
const ll p = 31;
// const ll m = 1e9 + 7;
const ll inf = 1e14;
const ll mod = 1e9 + 7;
#define x first
#define y second
#define pb push_back
#define mp make_pair
using pii = pair<ll, ll>;
ll powm(ll a, ll b) {
a = a % mod;
ll res = 1;
while (b) {
if (b & 1)
res = (res * a) % mod;
a = (a * a) % mod;
b >>= 1;
}
return res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll T = 1;
// cin >> T;
while (T--) {
string s;
cin >> s;
ll ct[1000];
memset(ct, 0, sizeof(ct));
for (int i = 0; i < 4; i++) {
ct[s[i]]++;
}
bool f = 0;
for (int i = 0; i < 4; i++) {
if (ct[s[i]] != 2 || ct[s[i]] != 0) {
f = 1;
}
}
if (f) {
cout << "No" << '\n';
} else {
cout << "Yes" << '\n';
}
}
return 0;
} | #include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/detail/standard_policies.hpp>
// using namespace __gnu_pbds;
using namespace std;
// template <typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
// tree_order_statistics_node_update>;
typedef long long int ll;
const ll N = 1e5 + 9;
const ll p = 31;
// const ll m = 1e9 + 7;
const ll inf = 1e14;
const ll mod = 1e9 + 7;
#define x first
#define y second
#define pb push_back
#define mp make_pair
using pii = pair<ll, ll>;
ll powm(ll a, ll b) {
a = a % mod;
ll res = 1;
while (b) {
if (b & 1)
res = (res * a) % mod;
a = (a * a) % mod;
b >>= 1;
}
return res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll T = 1;
// cin >> T;
while (T--) {
string s;
cin >> s;
ll ct[1000];
memset(ct, 0, sizeof(ct));
for (int i = 0; i < 4; i++) {
ct[s[i]]++;
}
bool f = 0;
for (int i = 0; i < 4; i++) {
if (ct[s[i]] != 2 && ct[s[i]] != 0) {
f = 1;
}
}
if (f) {
cout << "No" << '\n';
} else {
cout << "Yes" << '\n';
}
}
return 0;
} | [
"misc.opposites",
"control_flow.branch.if.condition.change"
] | 793,748 | 793,749 | u656299685 | cpp |
p02987 | #include <iostream>
#include <string>
using namespace std;
int main() {
string a[2];
int count1 = 0;
int count2 = 0;
string S;
cin >> S;
for (int i = 1; i < 4; i++) {
if (S[0] == S[i]) {
count1++;
} else {
a[count2] = S[i];
count2++;
}
}
if (count1 == 1 and a[0] == a[1]) {
cout << "Yes";
} else {
cout << "No";
}
return 0;
}
| #include <iostream>
#include <string>
using namespace std;
int main() {
string a[4];
int count1 = 0;
int count2 = 0;
string S;
cin >> S;
for (int i = 1; i < 4; i++) {
if (S[0] == S[i]) {
count1++;
} else {
a[count2] = S[i];
count2++;
}
}
if (count1 == 1 and a[0] == a[1]) {
cout << "Yes";
} else {
cout << "No";
}
return 0;
} | [
"literal.number.change",
"variable_declaration.array_dimensions.change"
] | 793,750 | 793,751 | u092669258 | cpp |
p02987 | #include <bits/stdc++.h>
using namespace std;
int main() {
vector<char> s;
for (int i = 0; i < 4; i++) {
cin >> s.at(i);
}
sort(s.begin(), s.end());
if (s.at(0) == s.at(1) && s.at(1) != s.at(2) && s.at(2) == s.at(3)) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
vector<char> s(4);
for (int i = 0; i <= 3; i++) {
cin >> s.at(i);
}
sort(s.begin(), s.end());
if (s.at(0) == s.at(1) && s.at(1) != s.at(2) && s.at(2) == s.at(3)) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
| [
"call.arguments.add",
"control_flow.loop.for.condition.change"
] | 793,754 | 793,755 | u457196771 | cpp |
p02987 | #include <iostream>
using namespace std;
int main() {
double a0;
string S;
cin >> S;
char c0 = S[0];
char c1 = S[1];
char c2 = S[2];
char c3 = S[3];
a0 = 0.0;
if (c0 == c1) {
if ((c2 == c3) && (c0 != c2)) {
a0 = 1.0;
}
}
if (c0 == c2) {
if ((c1 == c3) && (c0 != c1)) {
a0 = 1.0;
}
}
if (c0 == c3) {
if ((c1 == c2) && (c0 != c1)) {
a0 = 1.0;
}
}
if (a0 == 1) {
cout << "Yse" << endl;
} else {
cout << "No" << endl;
}
return 0;
} | #include <iostream>
using namespace std;
int main() {
double a0;
string S;
cin >> S;
char c0 = S[0];
char c1 = S[1];
char c2 = S[2];
char c3 = S[3];
a0 = 0.0;
if (c0 == c1) {
if ((c2 == c3) && (c0 != c2)) {
a0 = 1.0;
}
}
if (c0 == c2) {
if ((c1 == c3) && (c0 != c1)) {
a0 = 1.0;
}
}
if (c0 == c3) {
if ((c1 == c2) && (c0 != c1)) {
a0 = 1.0;
}
}
if (a0 == 1) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
}
| [
"literal.string.change",
"io.output.change"
] | 793,756 | 793,757 | u170116087 | cpp |
p02987 | #include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main() {
char S[4];
cin >> S;
int count = 0;
if (S[0] == S[1]) {
count++;
}
if (S[0] == S[2]) {
count++;
}
if (S[0] == S[3]) {
count++;
}
if (S[1] == S[2]) {
count++;
}
if (S[1] == S[3]) {
count++;
}
if (S[2] == S[3]) {
count++;
}
if (count == 2) {
cout << "yes";
}
if (count != 2) {
cout << "no";
}
return 0;
}
| #include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main() {
char S[4];
cin >> S;
int count = 0;
if (S[0] == S[1]) {
count++;
}
if (S[0] == S[2]) {
count++;
}
if (S[0] == S[3]) {
count++;
}
if (S[1] == S[2]) {
count++;
}
if (S[1] == S[3]) {
count++;
}
if (S[2] == S[3]) {
count++;
}
if (count == 2) {
cout << "Yes";
}
if (count != 2) {
cout << "No";
}
return 0;
}
| [
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 793,758 | 793,759 | u928636359 | cpp |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.