problem_id
stringlengths 6
6
| language
stringclasses 2
values | original_status
stringclasses 3
values | original_src
stringlengths 19
243k
| changed_src
stringlengths 19
243k
| change
stringclasses 3
values | i1
int64 0
8.44k
| i2
int64 0
8.44k
| j1
int64 0
8.44k
| j2
int64 0
8.44k
| error
stringclasses 270
values | stderr
stringlengths 0
226k
|
---|---|---|---|---|---|---|---|---|---|---|---|
p03221 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;
#define times(n) for (int i = 0; i < n; i++)
int main() {
int n, m, j;
scanf("%d%d", &n, &m);
vector<vector<int>> s(n + 1);
int p[m], y[m];
times(m) scanf("%d%d", &p[i], &y[i]), s[p[i]].push_back(y[i]);
times(n) sort(s[i + 1].begin(), s[i + 1].end());
times(m) j = find(s[p[i]].begin(), s[p[i]].end(), y[i]) - s[p[i]].begin() + 1,
printf("%06d%06d\n", p[i], j);
} | #include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;
#define times(n) for (int i = 0; i < n; i++)
int main() {
int n, m, j;
scanf("%d%d", &n, &m);
vector<vector<int>> s(n + 1);
int p[m], y[m];
times(m) scanf("%d%d", &p[i], &y[i]), s[p[i]].push_back(y[i]);
times(n) sort(s[i + 1].begin(), s[i + 1].end());
times(m) j =
lower_bound(s[p[i]].begin(), s[p[i]].end(), y[i]) - s[p[i]].begin() + 1,
printf("%06d%06d\n", p[i], j);
} | replace | 12 | 13 | 12 | 14 | TLE | |
p03221 | C++ | Time Limit Exceeded | #include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N, M;
cin >> N >> M;
vector<pair<int, int>> pys;
vector<int> mp[N + 1];
for (int i = 0; i < M; i++) {
int p, y;
cin >> p >> y;
pys.push_back(make_pair(p, y));
mp[p].push_back(y);
}
for (auto &e : mp) {
sort(e.begin(), e.end());
}
for (auto &p : pys) {
int pi = p.first;
vector<int> v = mp[pi];
auto iter = lower_bound(v.begin(), v.end(), p.second);
int x = iter - v.begin() + 1;
cout << setw(6) << setfill('0') << pi;
cout << setw(6) << setfill('0') << x;
cout << "\n";
}
return 0;
} | #include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N, M;
cin >> N >> M;
vector<pair<int, int>> pys;
vector<int> mp[N + 1];
for (int i = 0; i < M; i++) {
int p, y;
cin >> p >> y;
pys.push_back(make_pair(p, y));
mp[p].push_back(y);
}
for (auto &e : mp) {
sort(e.begin(), e.end());
}
for (auto &p : pys) {
int pi = p.first;
vector<int> &v = mp[pi];
auto iter = lower_bound(v.begin(), v.end(), p.second);
int x = iter - v.begin() + 1;
cout << setw(6) << setfill('0') << pi;
cout << setw(6) << setfill('0') << x;
cout << "\n";
}
return 0;
} | replace | 31 | 32 | 31 | 32 | TLE | |
p03221 | C++ | Runtime Error | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define PRINT(A) std::cout << (#A) << ":" << (A) << std::endl;
typedef long long int ll;
const int MOD = 1e9 + 7;
const int INF = 1e9;
using namespace std;
int main() {
int N, M;
cin >> N >> M;
int P[N + 1], Y[M + 1];
vector<int> city[M + 1];
REP(i, M) {
cin >> P[i] >> Y[i];
city[P[i]].push_back(Y[i]);
}
REP(i, N) sort(city[i + 1].begin(), city[i + 1].end());
REP(i, M) {
printf("%012lld\n",
ll(P[i]) * 1000000 +
int(lower_bound(ALL(city[P[i]]), Y[i]) - city[P[i]].begin()) +
1);
}
}
| #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define PRINT(A) std::cout << (#A) << ":" << (A) << std::endl;
typedef long long int ll;
const int MOD = 1e9 + 7;
const int INF = 1e9;
using namespace std;
int main() {
int N, M;
cin >> N >> M;
int P[100000], Y[100000];
vector<int> city[100001];
REP(i, M) {
cin >> P[i] >> Y[i];
city[P[i]].push_back(Y[i]);
}
REP(i, N) sort(city[i + 1].begin(), city[i + 1].end());
REP(i, M) {
printf("%012lld\n",
ll(P[i]) * 1000000 +
int(lower_bound(ALL(city[P[i]]), Y[i]) - city[P[i]].begin()) +
1);
}
}
| replace | 15 | 17 | 15 | 17 | 0 | |
p03221 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
string buildString(int a, int b) {
stringstream ss;
stringstream ss2;
ss << a;
ss2 << b;
string as = ss.str();
for (int i = as.size(); i < 6; i++) {
as = '0' + as;
}
string bs = ss2.str();
for (int i = bs.size(); i < 6; i++) {
bs = '0' + bs;
}
return as + bs;
}
int main() {
int n, m;
int x, y;
cin >> n >> m;
vector<pair<pair<int, int>, int>> container;
for (int i = 0; i < m; i++) {
cin >> x >> y;
container.push_back(make_pair(make_pair(x, y), i));
}
sort(container.begin(), container.end());
int lastIndex = -1;
int cont = 1;
vector<string> ans(10005);
string s;
for (int i = 0; i < m; i++) {
if (lastIndex == -1) {
s = buildString(container[i].first.first, cont);
ans[container[i].second] = s;
lastIndex = container[i].first.first;
continue;
}
if (lastIndex == container[i].first.first) {
cont++;
s = buildString(container[i].first.first, cont);
ans[container[i].second] = s;
} else {
cont = 1;
s = buildString(container[i].first.first, cont);
ans[container[i].second] = s;
lastIndex = container[i].first.first;
}
}
for (int i = 0; i < m; i++) {
cout << ans[i] << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
string buildString(int a, int b) {
stringstream ss;
stringstream ss2;
ss << a;
ss2 << b;
string as = ss.str();
for (int i = as.size(); i < 6; i++) {
as = '0' + as;
}
string bs = ss2.str();
for (int i = bs.size(); i < 6; i++) {
bs = '0' + bs;
}
return as + bs;
}
int main() {
int n, m;
int x, y;
cin >> n >> m;
vector<pair<pair<int, int>, int>> container;
for (int i = 0; i < m; i++) {
cin >> x >> y;
container.push_back(make_pair(make_pair(x, y), i));
}
sort(container.begin(), container.end());
int lastIndex = -1;
int cont = 1;
vector<string> ans(100005);
string s;
for (int i = 0; i < m; i++) {
if (lastIndex == -1) {
s = buildString(container[i].first.first, cont);
ans[container[i].second] = s;
lastIndex = container[i].first.first;
continue;
}
if (lastIndex == container[i].first.first) {
cont++;
s = buildString(container[i].first.first, cont);
ans[container[i].second] = s;
} else {
cont = 1;
s = buildString(container[i].first.first, cont);
ans[container[i].second] = s;
lastIndex = container[i].first.first;
}
}
for (int i = 0; i < m; i++) {
cout << ans[i] << endl;
}
return 0;
}
| replace | 49 | 50 | 49 | 50 | 0 | |
p03221 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;
using ll = long long;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
const int INF = 1001001001;
const long long INFLL = LLONG_MAX / 3;
const double eps = (1e-9);
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
map<int, vector<int>> mp;
ll n, m;
cin >> n >> m;
vector<pair<int, int>> yp1, yp2;
rep(i, m) {
int p, y;
cin >> p >> y;
yp1.emplace_back(y, p);
yp2.emplace_back(y, p);
}
sort(ALL(yp1));
for (auto &p : yp1) {
mp[p.second].push_back(p.first);
}
for (auto &p : yp2) {
auto v = mp[p.second];
int num = int(lower_bound(ALL(v), p.first) - v.begin()) + 1;
printf("%06d%06d\n", p.second, num);
}
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;
using ll = long long;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
const int INF = 1001001001;
const long long INFLL = LLONG_MAX / 3;
const double eps = (1e-9);
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
map<int, vector<int>> mp;
ll n, m;
cin >> n >> m;
vector<pair<int, int>> yp1, yp2;
rep(i, m) {
int p, y;
cin >> p >> y;
yp1.emplace_back(y, p);
yp2.emplace_back(y, p);
}
sort(ALL(yp1));
for (auto &p : yp1) {
mp[p.second].push_back(p.first);
}
for (auto &p : yp2) {
auto &v = mp[p.second];
int num = int(lower_bound(ALL(v), p.first) - v.begin()) + 1;
printf("%06d%06d\n", p.second, num);
}
return 0;
}
| replace | 52 | 53 | 52 | 53 | TLE | |
p03221 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define m0(x) memset(x, 0, sizeof(x))
int dx4[4] = {1, 0, -1, 0}, dy4[4] = {0, 1, 0, -1};
int main() {
int n, m;
cin >> n >> m;
vector<int> p(m), y(m), ansy(m);
vector<pii> city[10010];
for (int i = 0; i < m; i++) {
cin >> p.at(i) >> y.at(i);
city[p.at(i) - 1].push_back(pii(y.at(i), i));
}
for (int i = 0; i < n; i++) {
sort(all(city[i]));
for (int j = 0; j < city[i].size(); j++) {
ansy.at(city[i].at(j).second) = j + 1;
}
}
for (int i = 0; i < m; i++) {
cout << setfill('0') << right << setw(6) << p.at(i);
cout << setfill('0') << right << setw(6) << ansy.at(i) << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define m0(x) memset(x, 0, sizeof(x))
int dx4[4] = {1, 0, -1, 0}, dy4[4] = {0, 1, 0, -1};
int main() {
int n, m;
cin >> n >> m;
vector<int> p(m), y(m), ansy(m);
vector<pii> city[100100];
for (int i = 0; i < m; i++) {
cin >> p.at(i) >> y.at(i);
city[p.at(i) - 1].push_back(pii(y.at(i), i));
}
for (int i = 0; i < n; i++) {
sort(all(city[i]));
for (int j = 0; j < city[i].size(); j++) {
ansy.at(city[i].at(j).second) = j + 1;
}
}
for (int i = 0; i < m; i++) {
cout << setfill('0') << right << setw(6) << p.at(i);
cout << setfill('0') << right << setw(6) << ansy.at(i) << endl;
}
return 0;
} | replace | 17 | 18 | 17 | 18 | 0 | |
p03221 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
static const int INF(1 << 30);
int main() {
int N, M;
cin >> N >> M;
vector<tuple<int, int, int>> city;
vector<pair<int, int>> ans(N);
rep(i, M) {
int p, y;
cin >> p >> y;
city.push_back(make_tuple(p, y, i));
}
sort(all(city));
int pref_prev = get<0>(city[0]);
// int pref_prev = city[0].first;
int cnt_city = 0;
rep(i, M) {
int pref_now = get<0>(city[i]);
// int pref_now = city[i].first;
if (pref_now == pref_prev) {
cnt_city++;
} else {
cnt_city = 1;
pref_prev = pref_now;
}
// printf("%06d%06d\n", pref_now, cnt_city);
int idx = get<2>(city[i]);
ans[idx] = make_pair(pref_now, cnt_city);
}
rep(i, M) { printf("%06d%06d\n", ans[i].first, ans[i].second); }
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
static const int INF(1 << 30);
int main() {
int N, M;
cin >> N >> M;
vector<tuple<int, int, int>> city;
vector<pair<int, int>> ans(M);
rep(i, M) {
int p, y;
cin >> p >> y;
city.push_back(make_tuple(p, y, i));
}
sort(all(city));
int pref_prev = get<0>(city[0]);
// int pref_prev = city[0].first;
int cnt_city = 0;
rep(i, M) {
int pref_now = get<0>(city[i]);
// int pref_now = city[i].first;
if (pref_now == pref_prev) {
cnt_city++;
} else {
cnt_city = 1;
pref_prev = pref_now;
}
// printf("%06d%06d\n", pref_now, cnt_city);
int idx = get<2>(city[i]);
ans[idx] = make_pair(pref_now, cnt_city);
}
rep(i, M) { printf("%06d%06d\n", ans[i].first, ans[i].second); }
return 0;
} | replace | 11 | 12 | 11 | 12 | 0 | |
p03221 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <numeric>
#include <sstream>
#include <utility>
#include <vector>
using namespace std;
using ll = long long int;
constexpr int INF = 1 << 29;
constexpr ll MOD = ll(1e9 + 7);
int n, m;
int p[100000];
ll y[100000];
vector<ll> yd[100001];
int main(void) {
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> p[i] >> y[i];
yd[p[i]].push_back(y[i]);
}
for (int i = 0; i < m; i++) {
sort(yd[p[i]].begin(), yd[p[i]].end());
}
for (int i = 0; i < m; i++) {
int cnt = int(lower_bound(yd[p[i]].begin(), yd[p[i]].end(), y[i]) -
yd[p[i]].begin()) +
1;
cout << setw(6) << std::right << setfill('0') << p[i];
cout << setw(6) << std::right << setfill('0') << cnt;
cout << endl;
}
return 0;
} | #include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <numeric>
#include <sstream>
#include <utility>
#include <vector>
using namespace std;
using ll = long long int;
constexpr int INF = 1 << 29;
constexpr ll MOD = ll(1e9 + 7);
int n, m;
int p[100000];
ll y[100000];
vector<ll> yd[100001];
int main(void) {
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> p[i] >> y[i];
yd[p[i]].push_back(y[i]);
}
for (int i = 0; i < n; i++) {
sort(yd[i + 1].begin(), yd[i + 1].end());
}
for (int i = 0; i < m; i++) {
int cnt = int(lower_bound(yd[p[i]].begin(), yd[p[i]].end(), y[i]) -
yd[p[i]].begin()) +
1;
cout << setw(6) << std::right << setfill('0') << p[i];
cout << setw(6) << std::right << setfill('0') << cnt;
cout << endl;
}
return 0;
} | replace | 27 | 29 | 27 | 29 | TLE | |
p03221 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
int n, mm;
cin >> n >> mm;
vector<vector<ll>> m(n);
vector<pair<int, ll>> v(mm);
for (int i = 0; i < mm; i++) {
cin >> v[i].first >> v[i].second;
m[v[i].first - 1].push_back(v[i].second);
}
for (int i = 0; i < n; i++)
sort(m[i].begin(), m[i].end());
for (int i = 0; i < mm; i++) {
int a = v[i].first;
ll b = v[i].second;
int x = find(m[a - 1].begin(), m[a - 1].end(), b) - m[a - 1].begin() + 1;
printf("%06d", a);
printf("%06d", x);
cout << endl;
}
} | #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
int n, mm;
cin >> n >> mm;
vector<vector<ll>> m(n);
vector<pair<int, ll>> v(mm);
for (int i = 0; i < mm; i++) {
cin >> v[i].first >> v[i].second;
m[v[i].first - 1].push_back(v[i].second);
}
for (int i = 0; i < n; i++)
sort(m[i].begin(), m[i].end());
for (int i = 0; i < mm; i++) {
int a = v[i].first;
ll b = v[i].second;
int x =
lower_bound(m[a - 1].begin(), m[a - 1].end(), b) - m[a - 1].begin() + 1;
printf("%06d", a);
printf("%06d", x);
cout << endl;
}
} | replace | 25 | 26 | 25 | 27 | TLE | |
p03221 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()
int main() {
int N, M;
cin >> N >> M;
vector<int> P(M), Y(M);
REP(i, M)
cin >> P[i] >> Y[i];
vector<int> vc[100001];
REP(i, M)
vc[P[i]].push_back(Y[i]);
REP(i, M)
sort(ALL(vc[P[i]]));
REP(i, M)
printf("%06d%06d\n", P[i],
lower_bound(ALL(vc[P[i]]), Y[i]) - vc[P[i]].begin() + 1);
return 0;
} | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()
int main() {
int N, M;
cin >> N >> M;
vector<int> P(M), Y(M);
REP(i, M)
cin >> P[i] >> Y[i];
vector<int> vc[100001];
REP(i, M)
vc[P[i]].push_back(Y[i]);
REP1(i, N)
sort(ALL(vc[i]));
REP(i, M)
printf("%06d%06d\n", P[i],
lower_bound(ALL(vc[P[i]]), Y[i]) - vc[P[i]].begin() + 1);
return 0;
} | replace | 24 | 26 | 24 | 26 | TLE | |
p03221 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
int P[M], Y[M];
for (int i = 0; i < M; i++) {
cin >> P[i] >> Y[i];
}
vector<int> vec[100001];
for (int i = 0; i < M; i++) {
vec[P[i]].push_back(Y[i]);
}
for (int i = 1; i <= N; i++) {
sort(vec[i].begin(), vec[i].end());
}
for (int i = 0; i < M; i++) {
printf("%06d%06d\n", P[i],
distance(vec[P[i]].begin(),
find(vec[P[i]].begin(), vec[P[i]].end(), Y[i])) +
1);
}
return 0;
} | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
int P[M], Y[M];
for (int i = 0; i < M; i++) {
cin >> P[i] >> Y[i];
}
vector<int> vec[100001];
for (int i = 0; i < M; i++) {
vec[P[i]].push_back(Y[i]);
}
for (int i = 1; i <= N; i++) {
sort(vec[i].begin(), vec[i].end());
}
for (int i = 0; i < M; i++) {
printf("%06d%06d\n", P[i],
lower_bound(vec[P[i]].begin(), vec[P[i]].end(), Y[i]) -
vec[P[i]].begin() + 1);
}
return 0;
} | replace | 20 | 23 | 20 | 22 | TLE | |
p03221 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, ll> P;
const ll mod = 1e9 + 7;
const ll INF = 1e9;
const ll MAXN = 1e9;
int main() {
int N, M;
cin >> N >> M;
vector<int> P;
vector<ll> Y;
vector<ll> PY[N + 1];
rep(i, M) {
int p;
ll y;
cin >> p >> y;
P.push_back(p);
Y.push_back(y);
PY[p].push_back(y);
}
rep(i, M) {
int p = P[i];
sort(PY[p].begin(), PY[p].end());
}
rep(i, M) {
auto iter = lower_bound(PY[P[i]].begin(), PY[P[i]].end(), Y[i]);
string birthnum = to_string(1 + iter - PY[P[i]].begin());
string barthzero = string(6 - birthnum.size(), '0');
string recnum = to_string(P[i]);
string reczero = string(6 - recnum.size(), '0');
string ans = reczero + recnum + barthzero + birthnum;
cout << ans << endl;
}
} | #include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, ll> P;
const ll mod = 1e9 + 7;
const ll INF = 1e9;
const ll MAXN = 1e9;
int main() {
int N, M;
cin >> N >> M;
vector<int> P;
vector<ll> Y;
vector<ll> PY[N + 1];
rep(i, M) {
int p;
ll y;
cin >> p >> y;
P.push_back(p);
Y.push_back(y);
PY[p].push_back(y);
}
for (int i = 1; i <= N; i++) {
sort(PY[i].begin(), PY[i].end());
}
rep(i, M) {
auto iter = lower_bound(PY[P[i]].begin(), PY[P[i]].end(), Y[i]);
string birthnum = to_string(1 + iter - PY[P[i]].begin());
string barthzero = string(6 - birthnum.size(), '0');
string recnum = to_string(P[i]);
string reczero = string(6 - recnum.size(), '0');
string ans = reczero + recnum + barthzero + birthnum;
cout << ans << endl;
}
} | replace | 33 | 36 | 33 | 35 | TLE | |
p03221 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
struct city {
int pref;
int year;
};
int main() {
int n, m;
cin >> n >> m;
vector<city> v;
for (int i = 0; i < m; i++) {
int p, y;
cin >> p >> y;
city c = {p, y};
v.push_back(c);
}
map<int, vector<int>> table;
for (int i = 0; i < m; i++) {
if (table.count(v[i].pref)) {
table[v[i].pref].push_back(v[i].year);
} else {
vector<int> tmp = {v[i].year};
table[v[i].pref] = tmp;
}
}
for (auto it = table.begin(); it != table.end(); it++) {
sort((it->second).begin(), (it->second).end());
}
for (int i = 0; i < m; i++) {
auto it = find(table[v[i].pref].begin(), table[v[i].pref].end(), v[i].year);
int index = distance(table[v[i].pref].begin(), it);
cout << setfill('0') << right << setw(6) << v[i].pref;
cout << setfill('0') << right << setw(6) << index + 1 << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
struct city {
int pref;
int year;
};
int main() {
int n, m;
cin >> n >> m;
vector<city> v;
for (int i = 0; i < m; i++) {
int p, y;
cin >> p >> y;
city c = {p, y};
v.push_back(c);
}
map<int, vector<int>> table;
for (int i = 0; i < m; i++) {
if (table.count(v[i].pref)) {
table[v[i].pref].push_back(v[i].year);
} else {
vector<int> tmp = {v[i].year};
table[v[i].pref] = tmp;
}
}
for (auto it = table.begin(); it != table.end(); it++) {
sort((it->second).begin(), (it->second).end());
}
for (int i = 0; i < m; i++) {
auto it = lower_bound(table[v[i].pref].begin(), table[v[i].pref].end(),
v[i].year);
int index = distance(table[v[i].pref].begin(), it);
cout << setfill('0') << right << setw(6) << v[i].pref;
cout << setfill('0') << right << setw(6) << index + 1 << endl;
}
} | replace | 35 | 36 | 35 | 37 | TLE | |
p03221 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n, m, x;
cin >> n >> m;
vector<int> c(n), d(n);
vector<vector<int>> e(n + 1);
for (int i = 0; i < m; i++) {
cin >> c[i] >> d[i];
e[c[i]].push_back(d[i]);
}
for (int i = 0; i < n + 1; i++) {
sort(e[i].begin(), e[i].end());
}
for (int i = 0; i < m; i++) {
x = lower_bound(e[c[i]].begin(), e[c[i]].end(), d[i]) - e[c[i]].begin() + 1;
printf("%06d", c[i]);
printf("%06d\n", x);
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n, m, x;
cin >> n >> m;
vector<int> c(m), d(m);
vector<vector<int>> e(n + 1);
for (int i = 0; i < m; i++) {
cin >> c[i] >> d[i];
e[c[i]].push_back(d[i]);
}
for (int i = 0; i < n + 1; i++) {
sort(e[i].begin(), e[i].end());
}
for (int i = 0; i < m; i++) {
x = lower_bound(e[c[i]].begin(), e[c[i]].end(), d[i]) - e[c[i]].begin() + 1;
printf("%06d", c[i]);
printf("%06d\n", x);
}
} | replace | 7 | 8 | 7 | 8 | 0 | |
p03221 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
vector<vector<int>> pre_year(100001);
vector<int> pre(100001);
vector<int> year(100001);
for (int i = 0; i < M; i++) {
cin >> pre[i] >> year[i];
pre_year[pre[i]].push_back(year[i]);
sort(pre_year[pre[i]].begin(), pre_year[pre[i]].end());
}
for (int i = 0; i < M; i++) {
cout << setfill('0') << right << setw(6) << pre[i];
auto a =
lower_bound(pre_year[pre[i]].begin(), pre_year[pre[i]].end(), year[i]);
string ab = to_string(a - pre_year[pre[i]].begin() + 1);
cout << setfill('0') << right << setw(6) << ab << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
vector<vector<int>> pre_year(100001);
vector<int> pre(100001);
vector<int> year(100001);
for (int i = 0; i < M; i++) {
cin >> pre[i] >> year[i];
pre_year[pre[i]].push_back(year[i]);
}
for (int i = 1; i <= N; i++) {
sort(pre_year[i].begin(), pre_year[i].end());
}
for (int i = 0; i < M; i++) {
cout << setfill('0') << right << setw(6) << pre[i];
auto a =
lower_bound(pre_year[pre[i]].begin(), pre_year[pre[i]].end(), year[i]);
string ab = to_string(a - pre_year[pre[i]].begin() + 1);
cout << setfill('0') << right << setw(6) << ab << endl;
}
}
| replace | 14 | 15 | 14 | 17 | TLE | |
p03221 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PA;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i, x) for (long long i = 0; i < x; i++)
#define repn(i, x) for (long long i = 1; i <= x; i++)
#define SORT(x) sort(x.begin(), x.end())
#define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end())
#define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin())
#define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin())
int main() {
long long N;
long long M;
scanf("%lld", &N);
scanf("%lld", &M);
vector<ll> Y(M - 1 + 1);
vector<ll> P(M - 1 + 1);
priority_queue<PA, vector<PA>, greater<PA>> que[N];
for (ll i = 0; i <= M - 1; i++) {
cin >> P[i];
cin >> Y[i];
P[i]--;
que[P[i]].push(PA(Y[i], i));
}
vector<ll> num(N);
rep(i, N) {
ll c = 1;
while (!que[i].empty()) {
num[que[i].top().second] = c;
c++;
que[i].pop();
}
}
rep(i, M) {
printf("%06lld", P[i] + 1);
printf("%06lld\n", num[i]);
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PA;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i, x) for (long long i = 0; i < x; i++)
#define repn(i, x) for (long long i = 1; i <= x; i++)
#define SORT(x) sort(x.begin(), x.end())
#define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end())
#define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin())
#define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin())
int main() {
long long N;
long long M;
scanf("%lld", &N);
scanf("%lld", &M);
vector<ll> Y(M - 1 + 1);
vector<ll> P(M - 1 + 1);
priority_queue<PA, vector<PA>, greater<PA>> que[N];
for (ll i = 0; i <= M - 1; i++) {
cin >> P[i];
cin >> Y[i];
P[i]--;
que[P[i]].push(PA(Y[i], i));
}
vector<ll> num(M);
rep(i, N) {
ll c = 1;
while (!que[i].empty()) {
num[que[i].top().second] = c;
c++;
que[i].pop();
}
}
rep(i, M) {
printf("%06lld", P[i] + 1);
printf("%06lld\n", num[i]);
}
return 0;
}
| replace | 33 | 34 | 33 | 34 | 0 | |
p03221 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 1e9;
int main() {
int n, m;
cin >> n >> m;
vector<int> v[n];
int p[m], y[m];
for (int i = 0; i < m; i++) {
cin >> p[i] >> y[i];
v[--p[i]].push_back(y[i]);
}
for (int i = 0; i < n; i++) {
sort(v[i].begin(), v[i].end());
// v[i].erase(unique(v[i].begin(),v[i].end()),v[i].end());
}
for (int i = 0; i < m; i++) {
int t = find(v[p[i]].begin(), v[p[i]].end(), y[i]) - v[p[i]].begin();
printf("%06d%06d\n", p[i] + 1, t + 1);
}
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 1e9;
int main() {
int n, m;
cin >> n >> m;
vector<int> v[n];
int p[m], y[m];
for (int i = 0; i < m; i++) {
cin >> p[i] >> y[i];
v[--p[i]].push_back(y[i]);
}
for (int i = 0; i < n; i++) {
sort(v[i].begin(), v[i].end());
// v[i].erase(unique(v[i].begin(),v[i].end()),v[i].end());
}
for (int i = 0; i < m; i++) {
int t = lower_bound(v[p[i]].begin(), v[p[i]].end(), y[i]) - v[p[i]].begin();
printf("%06d%06d\n", p[i] + 1, t + 1);
}
}
| replace | 20 | 21 | 20 | 21 | TLE | |
p03221 | C++ | Runtime Error | #include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, n) for (int64_t i = 0; i < (int64_t)n; i++)
#define REP_FOR(i, a, b) for (int64_t i = (int64_t)a; i < (int64_t)b; i++)
#define REP_REV(i, a, b) for (int64_t i = (int64_t)a; i > (int64_t)b; i--)
#define FORALL(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int64_t, int64_t> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int64_t> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int64_t infi = 1147483600;
const ll infl = 4e18 + 5;
const char EOL = '\n';
const ll MOD = 998244353;
int main() {
ll n, m;
;
cin >> n >> m;
vector<tuple<ll, ll, ll>> P(m);
for (ll i = 0; i < m; ++i) {
auto &p = P[i];
cin >> get<0>(p) >> get<1>(p);
get<2>(p) = i;
}
sort(P.begin(), P.end(), [&](auto &left, auto &right) -> bool {
return get<1>(left) < get<1>(right);
});
vector<ll> counter(n, 0);
for (auto &p : P) {
counter[get<0>(p)]++;
get<1>(p) = counter[get<0>(p)];
}
sort(P.begin(), P.end(), [&](auto &left, auto &right) -> bool {
return get<2>(left) < get<2>(right);
});
for (auto &p : P) {
printf("%06lld%06lld\n", get<0>(p), get<1>(p));
}
}
| #include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, n) for (int64_t i = 0; i < (int64_t)n; i++)
#define REP_FOR(i, a, b) for (int64_t i = (int64_t)a; i < (int64_t)b; i++)
#define REP_REV(i, a, b) for (int64_t i = (int64_t)a; i > (int64_t)b; i--)
#define FORALL(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int64_t, int64_t> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int64_t> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int64_t infi = 1147483600;
const ll infl = 4e18 + 5;
const char EOL = '\n';
const ll MOD = 998244353;
int main() {
ll n, m;
;
cin >> n >> m;
vector<tuple<ll, ll, ll>> P(m);
for (ll i = 0; i < m; ++i) {
auto &p = P[i];
cin >> get<0>(p) >> get<1>(p);
get<2>(p) = i;
}
sort(P.begin(), P.end(), [&](auto &left, auto &right) -> bool {
return get<1>(left) < get<1>(right);
});
map<ll, ll> counter;
for (auto &p : P) {
counter[get<0>(p)]++;
get<1>(p) = counter[get<0>(p)];
}
sort(P.begin(), P.end(), [&](auto &left, auto &right) -> bool {
return get<2>(left) < get<2>(right);
});
for (auto &p : P) {
printf("%06lld%06lld\n", get<0>(p), get<1>(p));
}
}
| replace | 56 | 57 | 56 | 57 | 0 | |
p03221 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#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 INF 1000000000000
using ll = long long;
int main() {
int n, m;
cin >> n >> m;
vector<ll> p(m), y(m);
vector<vector<ll>> py(n);
rep(i, m) {
cin >> p.at(i) >> y.at(i);
py.at(p.at(i) - 1).push_back(y.at(i));
}
rep(i, n) sort(py.at(p.at(i) - 1).begin(), py.at(p.at(i) - 1).end());
rep(i, m) printf("%012lld\n",
ll(p.at(i)) * 1000000 +
int(lower_bound(py.at(p.at(i) - 1).begin(),
py.at(p.at(i) - 1).end(), y.at(i)) -
py.at(p.at(i) - 1).begin()) +
1);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#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 INF 1000000000000
using ll = long long;
int main() {
int n, m;
cin >> n >> m;
vector<ll> p(m), y(m);
vector<vector<ll>> py(n);
rep(i, m) {
cin >> p.at(i) >> y.at(i);
py.at(p.at(i) - 1).push_back(y.at(i));
}
rep(i, n) sort(py.at(i).begin(), py.at(i).end());
rep(i, m) printf("%012lld\n",
ll(p.at(i)) * 1000000 +
int(lower_bound(py.at(p.at(i) - 1).begin(),
py.at(p.at(i) - 1).end(), y.at(i)) -
py.at(p.at(i) - 1).begin()) +
1);
return 0;
}
| replace | 17 | 18 | 17 | 18 | 0 | |
p03221 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int N, M;
cin >> N >> M;
vector<vector<pii>> PY(N + 1);
vector<pii> res(N);
for (int i = 0; i < M; i++) {
int p, y;
cin >> p >> y;
PY[p].push_back(make_pair(y, i));
}
for (int i = 0; i <= N; i++) {
if (PY[i].size() == 0)
continue;
sort(PY[i].begin(), PY[i].end());
for (int j = 0; j < PY[i].size(); j++)
res[PY[i][j].second] = make_pair(i, j + 1);
}
for (int i = 0; i < M; i++) {
cout << setfill('0') << right << setw(6) << res[i].first;
cout << setfill('0') << right << setw(6) << res[i].second << '\n';
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int N, M;
cin >> N >> M;
vector<vector<pii>> PY(N + 1);
vector<pii> res(M);
for (int i = 0; i < M; i++) {
int p, y;
cin >> p >> y;
PY[p].push_back(make_pair(y, i));
}
for (int i = 0; i <= N; i++) {
if (PY[i].size() == 0)
continue;
sort(PY[i].begin(), PY[i].end());
for (int j = 0; j < PY[i].size(); j++)
res[PY[i][j].second] = make_pair(i, j + 1);
}
for (int i = 0; i < M; i++) {
cout << setfill('0') << right << setw(6) << res[i].first;
cout << setfill('0') << right << setw(6) << res[i].second << '\n';
}
return 0;
}
| replace | 11 | 12 | 11 | 12 | 0 | |
p03221 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long int;
using dd = long double;
const ll MOD = 1e9 + 7;
const dd PI = 3.1415926435;
class UnionFind {
public:
UnionFind(int N) : par(N) {
for (ll i = 0; i < N; i++) {
par[i] = i;
}
}
int root(int x) {
if (par[x] == x)
return x;
return par[x] = root(par[x]);
}
void unite(int x, int y) {
int rx = root(x);
int ry = root(y);
if (rx == ry)
return;
par[rx] = ry;
}
bool same(int x, int y) {
int rx = root(x);
int ry = root(y);
return rx == ry;
}
private:
vector<int> par;
};
ll gcd(ll a, ll b) {
if (a % b == 0) {
return b;
}
return gcd(b, a % b);
}
ll fact(ll n) {
if (n == 0) {
return 1;
}
if (n == 1) {
return 1;
}
return n * fact(n - 1) % MOD;
}
ll pow_fast(ll n, ll k) {
if (k == 0) {
return 1;
}
if (k == 1) {
return n;
}
if (k % 2 == 0) {
ll tmp = pow_fast(n, k / 2LL);
return tmp * tmp % MOD;
} else {
ll tmp = pow_fast(n, k / 2LL);
tmp *= tmp;
tmp %= MOD;
return tmp * n % MOD;
}
}
map<ll, ll> sosuu(ll n) {
map<ll, ll> res;
for (ll i = 2; i * i <= n; i++) {
while (n % i == 0) {
res[i] += 1;
n /= i;
}
}
if (n != 1) {
res[n] += 1;
}
return res;
}
struct Dish {
ll time;
ll taste;
};
static ll FACTORIAL[10000010] = {};
ll nCk(ll n, ll k) {
if (FACTORIAL[1] == 0) {
FACTORIAL[0] = 1;
FACTORIAL[1] = 1;
for (ll i = 2; i <= 10000000; i++) {
FACTORIAL[i] = FACTORIAL[i - 1] * i;
FACTORIAL[i] %= MOD;
}
}
ll N_fact = FACTORIAL[n];
ll K_fact = pow_fast(FACTORIAL[k], MOD - 2);
ll N_K_fact = pow_fast(FACTORIAL[n - k], MOD - 2);
ll ret = N_fact;
ret %= MOD;
ret *= K_fact;
ret %= MOD;
ret *= N_K_fact;
ret %= MOD;
return ret;
}
void solve(string s, ll K) {
ll sum = 0;
for (ll i = s.size(); i <= s.size() + K; i++) {
// 25
ll cnt = pow_fast(25, i - s.size()) % MOD;
cnt *= nCk(i - 1, s.size() - 1);
cnt %= MOD;
// 26
cnt *= pow_fast(26, s.size() + K - i);
cnt %= MOD;
sum += cnt;
sum %= MOD;
}
cout << sum << endl;
return;
}
vector<string> explode(string s, char delim) {
vector<string> ret;
string cur;
for (ll i = 0; i < s.size(); i++) {
if (s[i] == delim) {
ret.push_back(cur);
cur.clear();
continue;
}
cur += s[i];
}
if (cur.size() != 0) {
ret.push_back(cur);
}
return ret;
}
int main() {
ll N, M;
cin >> N >> M;
vector<pair<ll, ll>> mul(N + 1);
vector<map<ll, ll>> order(N + 1);
for (ll i = 0; i < M; i++) {
ll pi, yi;
cin >> pi >> yi;
mul[i] = {pi, yi};
order[pi][yi] += 1;
}
for (ll i = 1; i <= N; i++) {
ll num = 1;
for (auto &&e : order[i]) {
order[i][e.first] = num;
num += 1;
}
}
for (ll i = 0; i < M; i++) {
cout << fixed << setw(6) << setfill('0') << mul[i].first;
cout << fixed << setw(6) << setfill('0')
<< order[mul[i].first][mul[i].second];
cout << endl;
}
} | #include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long int;
using dd = long double;
const ll MOD = 1e9 + 7;
const dd PI = 3.1415926435;
class UnionFind {
public:
UnionFind(int N) : par(N) {
for (ll i = 0; i < N; i++) {
par[i] = i;
}
}
int root(int x) {
if (par[x] == x)
return x;
return par[x] = root(par[x]);
}
void unite(int x, int y) {
int rx = root(x);
int ry = root(y);
if (rx == ry)
return;
par[rx] = ry;
}
bool same(int x, int y) {
int rx = root(x);
int ry = root(y);
return rx == ry;
}
private:
vector<int> par;
};
ll gcd(ll a, ll b) {
if (a % b == 0) {
return b;
}
return gcd(b, a % b);
}
ll fact(ll n) {
if (n == 0) {
return 1;
}
if (n == 1) {
return 1;
}
return n * fact(n - 1) % MOD;
}
ll pow_fast(ll n, ll k) {
if (k == 0) {
return 1;
}
if (k == 1) {
return n;
}
if (k % 2 == 0) {
ll tmp = pow_fast(n, k / 2LL);
return tmp * tmp % MOD;
} else {
ll tmp = pow_fast(n, k / 2LL);
tmp *= tmp;
tmp %= MOD;
return tmp * n % MOD;
}
}
map<ll, ll> sosuu(ll n) {
map<ll, ll> res;
for (ll i = 2; i * i <= n; i++) {
while (n % i == 0) {
res[i] += 1;
n /= i;
}
}
if (n != 1) {
res[n] += 1;
}
return res;
}
struct Dish {
ll time;
ll taste;
};
static ll FACTORIAL[10000010] = {};
ll nCk(ll n, ll k) {
if (FACTORIAL[1] == 0) {
FACTORIAL[0] = 1;
FACTORIAL[1] = 1;
for (ll i = 2; i <= 10000000; i++) {
FACTORIAL[i] = FACTORIAL[i - 1] * i;
FACTORIAL[i] %= MOD;
}
}
ll N_fact = FACTORIAL[n];
ll K_fact = pow_fast(FACTORIAL[k], MOD - 2);
ll N_K_fact = pow_fast(FACTORIAL[n - k], MOD - 2);
ll ret = N_fact;
ret %= MOD;
ret *= K_fact;
ret %= MOD;
ret *= N_K_fact;
ret %= MOD;
return ret;
}
void solve(string s, ll K) {
ll sum = 0;
for (ll i = s.size(); i <= s.size() + K; i++) {
// 25
ll cnt = pow_fast(25, i - s.size()) % MOD;
cnt *= nCk(i - 1, s.size() - 1);
cnt %= MOD;
// 26
cnt *= pow_fast(26, s.size() + K - i);
cnt %= MOD;
sum += cnt;
sum %= MOD;
}
cout << sum << endl;
return;
}
vector<string> explode(string s, char delim) {
vector<string> ret;
string cur;
for (ll i = 0; i < s.size(); i++) {
if (s[i] == delim) {
ret.push_back(cur);
cur.clear();
continue;
}
cur += s[i];
}
if (cur.size() != 0) {
ret.push_back(cur);
}
return ret;
}
int main() {
ll N, M;
cin >> N >> M;
vector<pair<ll, ll>> mul(M + 1);
vector<map<ll, ll>> order(N + 1);
for (ll i = 0; i < M; i++) {
ll pi, yi;
cin >> pi >> yi;
mul[i] = {pi, yi};
order[pi][yi] += 1;
}
for (ll i = 1; i <= N; i++) {
ll num = 1;
for (auto &&e : order[i]) {
order[i][e.first] = num;
num += 1;
}
}
for (ll i = 0; i < M; i++) {
cout << fixed << setw(6) << setfill('0') << mul[i].first;
cout << fixed << setw(6) << setfill('0')
<< order[mul[i].first][mul[i].second];
cout << endl;
}
} | replace | 172 | 173 | 172 | 173 | 0 | |
p03221 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, M;
int p[100001], y[100001];
vector<int> vec[100001];
cin >> N >> M;
for (int i = 0; i < M; i++) {
cin >> p[i] >> y[i];
vec[p[i]].push_back(y[i]);
}
for (int i = 0; i < N; i++) {
sort(vec[i + 1].begin(), vec[i + 1].end());
}
for (int i = 0; i < M; i++) {
printf("%06d", p[i]);
for (int j = 0; j < vec[p[i]].size(); j++) {
if (vec[p[i]][j] == y[i]) {
printf("%06d", j + 1);
break;
}
}
cout << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int N, M;
int p[100001], y[100001];
vector<int> vec[100001];
cin >> N >> M;
for (int i = 0; i < M; i++) {
cin >> p[i] >> y[i];
vec[p[i]].push_back(y[i]);
}
for (int i = 0; i < N; i++) {
sort(vec[i + 1].begin(), vec[i + 1].end());
}
for (int i = 0; i < M; i++) {
printf("%06d", p[i]);
int j = lower_bound(vec[p[i]].begin(), vec[p[i]].end(), y[i]) -
vec[p[i]].begin() + 1;
printf("%06d", j);
cout << endl;
}
return 0;
}
| replace | 18 | 24 | 18 | 21 | TLE | |
p03221 | C++ | Time Limit Exceeded |
// include
//------------------------------------------
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
// conversion
//------------------------------------------
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T> inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
// math
//-------------------------------------------
template <class T> inline T sqr(T x) { return x * x; }
// typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
// container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c) \
for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define EXISTch(s, c) \
((((s).find_first_of(c)) != std::string::npos) ? 1 : 0) // cがあれば1 if(1)
#define SORT(c) sort((c).begin(), (c).end())
// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define loop(n) FOR(i, 0, n)
#define rrep(i, a, b) for (int i = (a); i >= (b); --i)
// constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007; // 10^9+7
const LL INF2 = (LL)100000000000000000; // 10^18
int main() {
int n, m;
cin >> n >> m;
vector<vector<int>> tb(n);
vector<int> p(m);
vector<int> y(m);
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
p[i] = a;
y[i] = b;
tb[a].push_back(b);
}
for (int i = 0; i < n; i++) {
sort(tb[i].begin(), tb[i].end());
}
for (int i = 0; i < m; i++) {
cout << setfill('0') << setw(6) << p[i] + 1;
auto itr = find(tb[p[i]].begin(), tb[p[i]].end(), y[i]);
int rank = itr - tb[p[i]].begin() + 1;
cout << setfill('0') << setw(6) << rank << endl;
}
} |
// include
//------------------------------------------
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
// conversion
//------------------------------------------
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T> inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
// math
//-------------------------------------------
template <class T> inline T sqr(T x) { return x * x; }
// typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
// container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c) \
for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define EXISTch(s, c) \
((((s).find_first_of(c)) != std::string::npos) ? 1 : 0) // cがあれば1 if(1)
#define SORT(c) sort((c).begin(), (c).end())
// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define loop(n) FOR(i, 0, n)
#define rrep(i, a, b) for (int i = (a); i >= (b); --i)
// constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007; // 10^9+7
const LL INF2 = (LL)100000000000000000; // 10^18
int main() {
int n, m;
cin >> n >> m;
vector<vector<int>> tb(n);
vector<int> p(m);
vector<int> y(m);
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
p[i] = a;
y[i] = b;
tb[a].push_back(b);
}
for (int i = 0; i < n; i++) {
sort(tb[i].begin(), tb[i].end());
}
for (int i = 0; i < m; i++) {
cout << setfill('0') << setw(6) << p[i] + 1;
auto itr = lower_bound(tb[p[i]].begin(), tb[p[i]].end(), y[i]);
int rank = itr - tb[p[i]].begin() + 1;
cout << setfill('0') << setw(6) << rank << endl;
}
} | replace | 105 | 106 | 105 | 106 | TLE | |
p03221 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007
#define PI 3.141592653589793
const int INF = 100000000;
int dx[] = {0, 1, -1, 0, 1, -1, 1, -1};
int dy[] = {1, 0, 0, -1, 1, -1, -1, 1};
int main() {
int n, m;
cin >> n >> m;
vector<tuple<int, int, int, int>> v;
for (int i = 1; i <= m; i++) {
int p, y, x = 0;
cin >> p >> y;
v.emplace_back(p, y, x, i);
}
sort(v.begin(), v.end());
int tmp = 0;
int num = 1;
for (auto &t : v) {
if (get<0>(t) != tmp) {
tmp = get<0>(t);
num = 1;
get<2>(t) = num;
num++;
} else {
get<2>(t) = num;
num++;
}
}
for (int i = 1; i <= m; i++) {
for (auto t : v) {
if (get<3>(t) == i) {
printf("%06d", get<0>(t));
printf("%06d\n", get<2>(t));
}
}
}
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007
#define PI 3.141592653589793
const int INF = 100000000;
int dx[] = {0, 1, -1, 0, 1, -1, 1, -1};
int dy[] = {1, 0, 0, -1, 1, -1, -1, 1};
int main() {
int n, m;
cin >> n >> m;
vector<tuple<int, int, int, int>> v;
for (int i = 1; i <= m; i++) {
int p, y, x = 0;
cin >> p >> y;
v.emplace_back(p, y, x, i);
}
sort(v.begin(), v.end());
int tmp = 0;
int num = 1;
for (auto &t : v) {
if (get<0>(t) != tmp) {
tmp = get<0>(t);
num = 1;
get<2>(t) = num;
num++;
} else {
get<2>(t) = num;
num++;
}
}
vector<tuple<int, int, int, int>> ans(m + 1);
for (auto t : v) {
ans[get<3>(t)] = t;
}
for (auto t : ans) {
if (get<0>(t) == 0)
continue;
printf("%06d", get<0>(t));
printf("%06d\n", get<2>(t));
}
}
| replace | 33 | 40 | 33 | 42 | TLE | |
p03221 | C++ | Runtime Error | #include <algorithm>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;
int main() {
// 入力
long N, M;
cin >> N >> M;
vector<long> P(M);
vector<pair<pair<long, long>, long>> cities(M);
for (long i = 0; i < M; i++) {
long Y;
cin >> P[i] >> Y;
cities[i] = make_pair(make_pair(Y, P[i]), i);
}
// 昇順にソート
sort(cities.begin(), cities.end());
vector<long> number(M);
vector<long> count(N);
for (long i = 0; i < cities.size(); i++) {
// 県に属した市iのカウントを計算する
count[cities[i].first.second]++;
// 入力時の順番のindexの番号配列に対して、カウントを代入する
number[cities[i].second] = count[cities[i].first.second];
}
// 出力
for (long i = 0; i < M; i++) {
// ゼロ埋め対応
cout << setfill('0') << right << setw(6) << P[i];
cout << setfill('0') << right << setw(6) << number[i];
// 改行
cout << endl;
}
return 0;
} | #include <algorithm>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;
int main() {
// 入力
long N, M;
cin >> N >> M;
vector<long> P(M);
vector<pair<pair<long, long>, long>> cities(M);
for (long i = 0; i < M; i++) {
long Y;
cin >> P[i] >> Y;
cities[i] = make_pair(make_pair(Y, P[i]), i);
}
// 昇順にソート
sort(cities.begin(), cities.end());
vector<long> number(M);
vector<long> count(N + 1);
for (long i = 0; i < cities.size(); i++) {
// 県に属した市iのカウントを計算する
count[cities[i].first.second]++;
// 入力時の順番のindexの番号配列に対して、カウントを代入する
number[cities[i].second] = count[cities[i].first.second];
}
// 出力
for (long i = 0; i < M; i++) {
// ゼロ埋め対応
cout << setfill('0') << right << setw(6) << P[i];
cout << setfill('0') << right << setw(6) << number[i];
// 改行
cout << endl;
}
return 0;
} | replace | 24 | 25 | 24 | 25 | 0 | |
p03221 | C++ | Runtime Error | #include <algorithm>
#include <assert.h>
#include <bitset>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <vector>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
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 / gcd(a, b) * b; }
inline double nCr(const int n, int r) {
if (n == 0) {
return 0;
}
if (r == 0) {
return 1;
}
if (r == 1) {
return n;
}
if (n == r) {
return 1;
}
if (r > n / 2) {
r = n / 2;
}
double result = 1;
for (double i = 1; i <= r; i++) {
result *= (n - i + 1) / i;
}
return (result);
}
template <typename T> T seinomi(T a) {
if (a > 0) {
return a;
} else {
return 0;
}
}
template <typename T>
map<T, T> soinsuubunkai(T n) // 連想配列[素因数f.first][個数f.second]
{
map<T, T> ret;
for (T i = 2; i * i <= n; i++) {
while (n % i == 0) {
ret[i]++;
n /= i;
}
}
if (n != 1)
ret[n] = 1;
return ret;
}
template <typename T> T ketasuu(T num) { return std::to_string(num).length(); }
int kaizyou(int k) {
int sum = 1;
for (int i = 1; i <= k; ++i) {
sum *= i;
}
return sum;
}
template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value) {
while (first != last) {
*first++ = value;
++value;
}
}
// nの階乗を計算
int factorial(int n) {
int answer = 1;
while (n > 1) {
answer *= n;
n--;
}
return answer;
}
int comb(int n, int r) {
return factorial(n) / (factorial(r) * factorial(n - r));
}
long long modpow(long long a, long long n, long long mod) {
long long res = 1;
while (n > 0) {
if (n & 1)
res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
// 小数点以下10桁テンプレート(main関数内の最初に貼付け)
// std::cout << std::fixed << std::setprecision(10);
//----------------------------------------------------------------
int main() {
ll n, m;
cin >> n >> m;
ll y, p;
vector<vector<ll>> a(m, vector<ll>());
map<ll, ll> b, c, d;
for (int i = 0; i < m; i++) {
cin >> p >> y;
a[p].push_back(y);
b[y] = p;
c[i] = y;
}
for (int i = 1; i <= n; i++) {
sort(a[i].begin(), a[i].end());
}
for (int i = 1; i <= n; i++) {
ll cnt = 1;
for (auto f : a[i]) {
d[f] = cnt;
cnt++;
}
}
for (int i = 0; i < m; i++) {
for (int j = 0; j < 6 - ketasuu(b[c[i]]); j++) {
cout << "0";
}
cout << b[c[i]];
for (int j = 0; j < 6 - ketasuu(d[c[i]]); j++) {
cout << "0";
}
cout << d[c[i]] << endl;
}
}
| #include <algorithm>
#include <assert.h>
#include <bitset>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <vector>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
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 / gcd(a, b) * b; }
inline double nCr(const int n, int r) {
if (n == 0) {
return 0;
}
if (r == 0) {
return 1;
}
if (r == 1) {
return n;
}
if (n == r) {
return 1;
}
if (r > n / 2) {
r = n / 2;
}
double result = 1;
for (double i = 1; i <= r; i++) {
result *= (n - i + 1) / i;
}
return (result);
}
template <typename T> T seinomi(T a) {
if (a > 0) {
return a;
} else {
return 0;
}
}
template <typename T>
map<T, T> soinsuubunkai(T n) // 連想配列[素因数f.first][個数f.second]
{
map<T, T> ret;
for (T i = 2; i * i <= n; i++) {
while (n % i == 0) {
ret[i]++;
n /= i;
}
}
if (n != 1)
ret[n] = 1;
return ret;
}
template <typename T> T ketasuu(T num) { return std::to_string(num).length(); }
int kaizyou(int k) {
int sum = 1;
for (int i = 1; i <= k; ++i) {
sum *= i;
}
return sum;
}
template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value) {
while (first != last) {
*first++ = value;
++value;
}
}
// nの階乗を計算
int factorial(int n) {
int answer = 1;
while (n > 1) {
answer *= n;
n--;
}
return answer;
}
int comb(int n, int r) {
return factorial(n) / (factorial(r) * factorial(n - r));
}
long long modpow(long long a, long long n, long long mod) {
long long res = 1;
while (n > 0) {
if (n & 1)
res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
// 小数点以下10桁テンプレート(main関数内の最初に貼付け)
// std::cout << std::fixed << std::setprecision(10);
//----------------------------------------------------------------
int main() {
ll n, m;
cin >> n >> m;
ll y, p;
vector<vector<ll>> a(100010, vector<ll>());
map<ll, ll> b, c, d;
for (int i = 0; i < m; i++) {
cin >> p >> y;
a[p].push_back(y);
b[y] = p;
c[i] = y;
}
for (int i = 1; i <= n; i++) {
sort(a[i].begin(), a[i].end());
}
for (int i = 1; i <= n; i++) {
ll cnt = 1;
for (auto f : a[i]) {
d[f] = cnt;
cnt++;
}
}
for (int i = 0; i < m; i++) {
for (int j = 0; j < 6 - ketasuu(b[c[i]]); j++) {
cout << "0";
}
cout << b[c[i]];
for (int j = 0; j < 6 - ketasuu(d[c[i]]); j++) {
cout << "0";
}
cout << d[c[i]] << endl;
}
}
| replace | 145 | 146 | 145 | 146 | 0 | |
p03221 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;
typedef long long ll;
ll b[100000];
ll a[100000];
vector<ll> v[100000];
int main() {
ll n, m;
cin >> n >> m;
for (ll i = 0; i < m; i++) {
cin >> a[i] >> b[i];
v[a[i]].push_back(b[i]);
}
for (ll i = 1; i <= n; i++)
sort(v[i].begin(), v[i].end());
for (ll i = 0; i < m; i++) {
ll ans =
lower_bound(v[a[i]].begin(), v[a[i]].end(), b[i]) - v[a[i]].begin();
printf("%06lld%06lld\n", a[i], ans + 1);
}
return 0;
}
| #include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;
typedef long long ll;
ll b[100010];
ll a[100010];
vector<ll> v[100010];
int main() {
ll n, m;
cin >> n >> m;
for (ll i = 0; i < m; i++) {
cin >> a[i] >> b[i];
v[a[i]].push_back(b[i]);
}
for (ll i = 1; i <= n; i++)
sort(v[i].begin(), v[i].end());
for (ll i = 0; i < m; i++) {
ll ans =
lower_bound(v[a[i]].begin(), v[a[i]].end(), b[i]) - v[a[i]].begin();
printf("%06lld%06lld\n", a[i], ans + 1);
}
return 0;
}
| replace | 9 | 12 | 9 | 12 | 0 | |
p03221 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<int> p(m), y(m);
rep(i, m) cin >> p[i] >> y[i];
vector<vector<int>> cor(n + 1);
rep(i, m) { cor[p[i]].push_back(y[i]); }
rep(i, m) sort(cor[i].begin(), cor[i].end());
rep(i, m) {
int num = lower_bound(cor[p[i]].begin(), cor[p[i]].end(), y[i]) -
cor[p[i]].begin() + 1;
cout << setfill('0') << setw(6) << p[i] << setfill('0') << setw(6) << num
<< endl;
}
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<int> p(m), y(m);
rep(i, m) cin >> p[i] >> y[i];
vector<vector<int>> cor(n + 1);
rep(i, m) { cor[p[i]].push_back(y[i]); }
for (int i = 1; i <= n; i++)
sort(cor[i].begin(), cor[i].end());
rep(i, m) {
int num = lower_bound(cor[p[i]].begin(), cor[p[i]].end(), y[i]) -
cor[p[i]].begin() + 1;
cout << setfill('0') << setw(6) << p[i] << setfill('0') << setw(6) << num
<< endl;
}
}
| replace | 19 | 20 | 19 | 21 | 0 | |
p03221 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<vector<pair<ll, ll>>> p(m, vector<pair<ll, ll>>(0));
vector<string> id(m);
for (int i = 0; i < m; i++) {
ll place, year;
cin >> place >> year;
p[place - 1].push_back(make_pair(year, i));
}
for (int i = 0; i < n; i++) {
sort(p[i].begin(), p[i].end());
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < p[i].size(); j++) {
ostringstream ss;
ss << setw(6) << setfill('0') << to_string(i + 1);
string idi(ss.str());
ostringstream sl;
sl << setw(6) << setfill('0') << to_string(j + 1);
string idj(sl.str());
id[p[i][j].second] = idi + idj;
}
}
for (int i = 0; i < m; i++) {
cout << id[i] << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<vector<pair<ll, ll>>> p(n, vector<pair<ll, ll>>(0));
vector<string> id(m);
for (int i = 0; i < m; i++) {
ll place, year;
cin >> place >> year;
p[place - 1].push_back(make_pair(year, i));
}
for (int i = 0; i < n; i++) {
sort(p[i].begin(), p[i].end());
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < p[i].size(); j++) {
ostringstream ss;
ss << setw(6) << setfill('0') << to_string(i + 1);
string idi(ss.str());
ostringstream sl;
sl << setw(6) << setfill('0') << to_string(j + 1);
string idj(sl.str());
id[p[i][j].second] = idi + idj;
}
}
for (int i = 0; i < m; i++) {
cout << id[i] << endl;
}
return 0;
} | replace | 9 | 10 | 9 | 10 | 0 | |
p03221 | C++ | Runtime Error | #include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(), (x).end()
#define rrng(x) (x).rbegin(), (x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define SUM(x) accumulate(rng(x), 0)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define uni(x) x.erase(unique(rng(x)), x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1 << 30;
const ll INFLL = 1LL << 60;
// cout << fixed << setprecision(10);
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
int main() {
int n, m;
cin >> n >> m;
vi p(m), y(m);
vi yd[m + 1];
rep(i, m) {
cin >> p[i] >> y[i];
yd[p[i]].pb(y[i]);
}
rep(i, n) sort(yd[i + 1].begin(), yd[i + 1].end());
rep(i, m) printf("%06d%06d\n", p[i],
lower_bound(rng(yd[p[i]]), y[i]) - yd[p[i]].begin() + 1);
return 0;
} | #include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(), (x).end()
#define rrng(x) (x).rbegin(), (x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define SUM(x) accumulate(rng(x), 0)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define uni(x) x.erase(unique(rng(x)), x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1 << 30;
const ll INFLL = 1LL << 60;
// cout << fixed << setprecision(10);
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
int main() {
int n, m;
cin >> n >> m;
vi p(m), y(m);
vi yd[n + 1];
rep(i, m) {
cin >> p[i] >> y[i];
yd[p[i]].pb(y[i]);
}
rep(i, n) sort(yd[i + 1].begin(), yd[i + 1].end());
rep(i, m) printf("%06d%06d\n", p[i],
lower_bound(rng(yd[p[i]]), y[i]) - yd[p[i]].begin() + 1);
return 0;
} | replace | 48 | 49 | 48 | 49 | 0 | |
p03221 | C++ | Time Limit Exceeded | //------------------------------------------
// C++ templete
//------------------------------------------
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
using ll = long long;
#define endl "\n"
// typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;
// REPEAT
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
// container util
//------------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(), (a).end()
#define PRINT(V) \
for (auto v : (V)) \
cout << v << " "
#define SORT(V) sort((V).begin(), (V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
// constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI = acos(-1.0);
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
// math
//------------------------------------------
int QP(int a, int b) {
int ans = 1;
do {
if (b & 1)
ans = 1ll * ans * a % MOD;
a = 1ll * a * a % MOD;
} while (b >>= 1);
return ans;
}
int QP(int a, int b, int MOD) {
int ans = 1;
do {
if (b & 1)
ans = 1ll * ans * a % MOD;
a = 1ll * a * a % MOD;
} while (b >>= 1);
return ans;
}
int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }
// debug
//------------------------------------------
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) \
cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
<< " " << __FILE__ << endl;
// 動的計画法で役に立つ関数
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;
}
// 最大公約数と最小公倍数
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
ll g = gcd(a, b);
return a / g * b;
}
vector<vector<long long>> comb(int n) {
vector<vector<long long>> v(n + 1, vector<long long>(n + 1, 0));
for (int i = 0; i < v.size(); i++) {
v[i][0] = 1;
v[i][i] = 1;
}
for (int j = 1; j < v.size(); j++) {
for (int k = 1; k < j; k++) {
v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
}
}
return v;
}
string fill_in(int n) {
string S = to_string(n);
string ans;
REP(i, 6 - S.size()) { ans += "0"; }
ans += S;
return ans;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int N, M;
cin >> N >> M;
VI Y(M), P(M);
VVI A(N);
REP(i, M) {
int p, y;
cin >> P[i] >> Y[i];
A[P[i] - 1].pb(Y[i]);
}
REP(i, N) { SORT(A[i]); }
REP(i, M) {
int y = Y[i];
int p = P[i];
cout << fill_in(p);
int rank = 999999;
REP(j, M) {
if (y <= A[p - 1][j]) {
rank = j + 1;
break;
}
}
cout << fill_in(rank) << endl;
}
return 0;
}
| //------------------------------------------
// C++ templete
//------------------------------------------
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
using ll = long long;
#define endl "\n"
// typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;
// REPEAT
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
// container util
//------------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(), (a).end()
#define PRINT(V) \
for (auto v : (V)) \
cout << v << " "
#define SORT(V) sort((V).begin(), (V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
// constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI = acos(-1.0);
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
// math
//------------------------------------------
int QP(int a, int b) {
int ans = 1;
do {
if (b & 1)
ans = 1ll * ans * a % MOD;
a = 1ll * a * a % MOD;
} while (b >>= 1);
return ans;
}
int QP(int a, int b, int MOD) {
int ans = 1;
do {
if (b & 1)
ans = 1ll * ans * a % MOD;
a = 1ll * a * a % MOD;
} while (b >>= 1);
return ans;
}
int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }
// debug
//------------------------------------------
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) \
cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
<< " " << __FILE__ << endl;
// 動的計画法で役に立つ関数
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;
}
// 最大公約数と最小公倍数
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
ll g = gcd(a, b);
return a / g * b;
}
vector<vector<long long>> comb(int n) {
vector<vector<long long>> v(n + 1, vector<long long>(n + 1, 0));
for (int i = 0; i < v.size(); i++) {
v[i][0] = 1;
v[i][i] = 1;
}
for (int j = 1; j < v.size(); j++) {
for (int k = 1; k < j; k++) {
v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
}
}
return v;
}
string fill_in(int n) {
string S = to_string(n);
string ans;
REP(i, 6 - S.size()) { ans += "0"; }
ans += S;
return ans;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int N, M;
cin >> N >> M;
VI Y(M), P(M);
VVI A(N);
REP(i, M) {
int p, y;
cin >> P[i] >> Y[i];
A[P[i] - 1].pb(Y[i]);
}
REP(i, N) { SORT(A[i]); }
REP(i, M) {
int y = Y[i];
int p = P[i];
cout << fill_in(p);
int rank = upper_bound(ALL(A[p - 1]), y) - A[p - 1].begin();
cout << fill_in(rank) << endl;
}
return 0;
}
| replace | 140 | 147 | 140 | 141 | TLE | |
p03221 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<vector<int>> vec(n);
vector<pair<int, int>> city(m);
for (int i = 0; i < m; i++) {
int p, y;
cin >> p >> y;
vec[p - 1].push_back(y);
city[i] = make_pair(p - 1, y);
}
for (int i = 0; i < n; i++) {
sort(vec[i].begin(), vec[i].end());
}
for (auto &e : city) {
int p = e.first, y = e.second;
auto itr = find(vec[p].begin(), vec[p].end(), y);
printf("%06d", p + 1);
printf("%06d", (int)(itr - vec[p].begin()) + 1);
cout << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<vector<int>> vec(n);
vector<pair<int, int>> city(m);
for (int i = 0; i < m; i++) {
int p, y;
cin >> p >> y;
vec[p - 1].push_back(y);
city[i] = make_pair(p - 1, y);
}
for (int i = 0; i < n; i++) {
sort(vec[i].begin(), vec[i].end());
}
for (auto &e : city) {
int p = e.first, y = e.second;
auto itr = lower_bound(vec[p].begin(), vec[p].end(), y);
printf("%06d", p + 1);
printf("%06d", (int)(itr - vec[p].begin()) + 1);
cout << endl;
}
} | replace | 18 | 19 | 18 | 19 | TLE | |
p03221 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
int main(int argc, const char *argv[]) {
// ifstream in("input.txt");
// cin.rdbuf(in.rdbuf());
cin.tie(0);
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
vector<tuple<int, int, int>> p_yip(m); // year, id, prefecture
rep(i, m) {
int p, y;
cin >> p >> y;
--p;
p_yip[i] = {y, i, p};
}
sort(p_yip.begin(), p_yip.end());
vector<vector<int>> table(m); // [prefecture][city_id]
rep(i, m) { table[get<2>(p_yip[i])].push_back(get<1>(p_yip[i])); }
vector<string> vec_ans(m);
rep(prefecture, n) {
std::ostringstream sout_p;
sout_p << std::setfill('0') << std::setw(6) << prefecture + 1;
std::string str_p = sout_p.str();
for (int city = 0; city < table[prefecture].size(); ++city) {
std::ostringstream sout_c;
sout_c << std::setfill('0') << std::setw(6) << city + 1;
std::string str_c = sout_c.str();
vec_ans[table[prefecture][city]] = str_p + str_c;
}
}
rep(i, m) { cout << vec_ans[i] << endl; }
return 0;
} | #include <algorithm>
#include <cmath>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
int main(int argc, const char *argv[]) {
// ifstream in("input.txt");
// cin.rdbuf(in.rdbuf());
cin.tie(0);
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
vector<tuple<int, int, int>> p_yip(m); // year, id, prefecture
rep(i, m) {
int p, y;
cin >> p >> y;
--p;
p_yip[i] = {y, i, p};
}
sort(p_yip.begin(), p_yip.end());
vector<vector<int>> table(n); // [prefecture][city] -> city_id
rep(i, m) { table[get<2>(p_yip[i])].push_back(get<1>(p_yip[i])); }
vector<string> vec_ans(m);
rep(prefecture, n) {
std::ostringstream sout_p;
sout_p << std::setfill('0') << std::setw(6) << prefecture + 1;
std::string str_p = sout_p.str();
for (int city = 0; city < table[prefecture].size(); ++city) {
std::ostringstream sout_c;
sout_c << std::setfill('0') << std::setw(6) << city + 1;
std::string str_c = sout_c.str();
vec_ans[table[prefecture][city]] = str_p + str_c;
}
}
rep(i, m) { cout << vec_ans[i] << endl; }
return 0;
} | replace | 39 | 40 | 39 | 40 | 0 | |
p03221 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<pair<pair<long long, long long>, long long>> ypx(m);
vector<long long> ans(m);
vector<long long> cnt(n);
for (int i = 0; i < m; ++i) {
cin >> ypx[i].first.second >> ypx[i].first.first;
ypx[i].second = i;
}
sort(ypx.begin(), ypx.end());
for (int i = 0; i < m; ++i) {
long long pi = ypx[i].first.second;
cnt[pi]++;
ans[ypx[i].second] = pi * 1000000 + cnt[pi];
}
for (int i = 0; i < m; ++i)
printf("%012lld\n", ans[i]);
return 0;
} | #include <algorithm>
#include <cstdio>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<pair<pair<long long, long long>, long long>> ypx(m);
vector<long long> ans(m);
vector<long long> cnt(n + 1);
for (int i = 0; i < m; ++i) {
cin >> ypx[i].first.second >> ypx[i].first.first;
ypx[i].second = i;
}
sort(ypx.begin(), ypx.end());
for (int i = 0; i < m; ++i) {
long long pi = ypx[i].first.second;
cnt[pi]++;
ans[ypx[i].second] = pi * 1000000 + cnt[pi];
}
for (int i = 0; i < m; ++i)
printf("%012lld\n", ans[i]);
return 0;
} | replace | 13 | 14 | 13 | 14 | 0 | |
p03221 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;
typedef pair<int, Pii> P1;
#define rep(i, n) for (int i = 0; i < n; i++)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define mp1(a, b, c) P1(a, P(b, c))
#define get_arsize(a) (sizeof(a) / sizeof(a[0]))
const ll MOD = 1000000007;
const double EPS = 1e-10;
const int MAX = 200000;
int main() {
int n, m;
cin >> n >> m;
int p[100000], y[100000];
vector<ll> yd[100001];
rep(i, m) {
int pi, yi;
cin >> pi >> yi;
p[i] = pi;
y[i] = yi;
yd[pi].push_back(yi);
}
// 上記コードは1行で済む。
// rep (i,m) scanf ("%d%d",&p[i],&y[i]), yd[p[i]].push_back(y[i]);
rep(i, n) sor(yd[i + 1]);
rep(i, m) {
vector<ll> ydp = yd[p[i]]; // autoにすると4倍かかる
int index = int(lb(ydp, y[i]) - ydp.begin()) + 1;
printf("%012lld\n", ll(p[i]) * 1000000 + index);
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;
typedef pair<int, Pii> P1;
#define rep(i, n) for (int i = 0; i < n; i++)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define mp1(a, b, c) P1(a, P(b, c))
#define get_arsize(a) (sizeof(a) / sizeof(a[0]))
const ll MOD = 1000000007;
const double EPS = 1e-10;
const int MAX = 200000;
int main() {
int n, m;
cin >> n >> m;
int p[100000], y[100000];
vector<ll> yd[100001];
rep(i, m) {
int pi, yi;
cin >> pi >> yi;
p[i] = pi;
y[i] = yi;
yd[pi].push_back(yi);
}
// 上記コードは1行で済む。
// rep (i,m) scanf ("%d%d",&p[i],&y[i]), yd[p[i]].push_back(y[i]);
rep(i, n) sor(yd[i + 1]);
rep(i, m) {
// vector<ll> ydp = yd[p[i]]; => コピーされるのでNG。TLEを起こす。
vector<ll> *ydp = &yd[p[i]];
int index =
int(lower_bound(ydp->begin(), ydp->end(), y[i]) - ydp->begin()) + 1;
printf("%012lld\n", ll(p[i]) * 1000000 + index);
}
return 0;
}
| replace | 37 | 39 | 37 | 41 | TLE | |
p03221 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;
typedef pair<int, Pii> P1;
#define rep(i, n) for (int i = 0; i < n; i++)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define mp1(a, b, c) P1(a, P(b, c))
#define get_arsize(a) (sizeof(a) / sizeof(a[0]))
const ll MOD = 1000000007;
const double EPS = 1e-10;
const int MAX = 200000;
int main() {
int n, m;
cin >> n >> m;
int p[100000], y[100000];
vector<ll> yd[100001];
rep(i, m) {
int pi, yi;
cin >> pi >> yi;
p[i] = pi;
y[i] = yi;
yd[pi].push_back(yi);
}
// rep (i,m) scanf ("%d%d",&p[i],&y[i]), yd[p[i]].push_back(y[i]);
rep(i, n) sor(yd[i + 1]);
rep(i, m) {
auto year = yd[p[i]];
int index = int(lb(year, y[i]) - year.begin()) + 1;
printf("%012lld\n", ll(p[i]) * 1000000 + index);
}
// printf ("%012lld\n", ll(p[i])*1000000+ int(lb(yd[p[i]], y[i]) -
// yd[p[i]].begin())+1);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;
typedef pair<int, Pii> P1;
#define rep(i, n) for (int i = 0; i < n; i++)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define mp1(a, b, c) P1(a, P(b, c))
#define get_arsize(a) (sizeof(a) / sizeof(a[0]))
const ll MOD = 1000000007;
const double EPS = 1e-10;
const int MAX = 200000;
int main() {
int n, m;
cin >> n >> m;
int p[100000], y[100000];
vector<ll> yd[100001];
rep(i, m) {
int pi, yi;
cin >> pi >> yi;
p[i] = pi;
y[i] = yi;
yd[pi].push_back(yi);
}
// rep (i,m) scanf ("%d%d",&p[i],&y[i]), yd[p[i]].push_back(y[i]);
rep(i, n) sor(yd[i + 1]);
rep(i, m) {
int index = int(lb(yd[p[i]], y[i]) - yd[p[i]].begin()) + 1;
printf("%012lld\n", ll(p[i]) * 1000000 + index);
}
// printf ("%012lld\n", ll(p[i])*1000000+ int(lb(yd[p[i]], y[i]) -
// yd[p[i]].begin())+1);
return 0;
}
| replace | 36 | 38 | 36 | 37 | TLE | |
p03221 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;
typedef pair<int, Pii> P1;
#define rep(i, n) for (int i = 0; i < n; i++)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define mp1(a, b, c) P1(a, P(b, c))
#define get_arsize(a) (sizeof(a) / sizeof(a[0]))
const ll MOD = 1000000007;
const double EPS = 1e-10;
const int MAX = 200000;
int main() {
int n, m;
cin >> n >> m;
int p[100000], y[100000];
vector<ll> yearList[100001];
rep(i, m) {
int pi, yi;
cin >> pi >> yi;
p[i] = pi;
y[i] = yi;
yearList[pi].push_back(yi);
}
rep(i, n) sor(yearList[i + 1]);
rep(i, m) {
// cout.fill('0');
// cout << setw(6) << p[i];
auto year = yearList[p[i]];
int index = int(lb(year, y[i]) - year.begin()) + 1;
// cout << setw(6) << index << endl;
printf("%012lld\n", ll(p[i]) * 1000000 + index);
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;
typedef pair<int, Pii> P1;
#define rep(i, n) for (int i = 0; i < n; i++)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define mp1(a, b, c) P1(a, P(b, c))
#define get_arsize(a) (sizeof(a) / sizeof(a[0]))
const ll MOD = 1000000007;
const double EPS = 1e-10;
const int MAX = 200000;
int main() {
int n, m;
cin >> n >> m;
int p[100000], y[100000];
vector<ll> yd[100001];
rep(i, m) scanf("%d%d", &p[i], &y[i]), yd[p[i]].push_back(y[i]);
rep(i, n) sort(yd[i + 1].begin(), yd[i + 1].end());
rep(i, m) printf("%012lld\n",
ll(p[i]) * 1000000 +
int(lower_bound(yd[p[i]].begin(), yd[p[i]].end(), y[i]) -
yd[p[i]].begin()) +
1);
return 0;
}
| replace | 25 | 42 | 25 | 33 | TLE | |
p03221 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
vector<int> P(M), Y(M);
for (int i = 0; i < M; i++) {
cin >> P[i] >> Y[i];
P[i]--;
}
vector<vector<int>> vals(N);
for (int i = 0; i < M; i++) {
vals[P[i]].push_back(Y[i]);
}
for (int i = 0; i < M; i++) {
sort(vals[i].begin(), vals[i].end());
}
for (int i = 0; i < M; i++) {
int v = P[i];
printf("%06d", v + 1);
int id =
lower_bound(vals[v].begin(), vals[v].end(), Y[i]) - vals[v].begin();
printf("%06d\n", id + 1);
}
} | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
vector<int> P(M), Y(M);
for (int i = 0; i < M; i++) {
cin >> P[i] >> Y[i];
P[i]--;
}
vector<vector<int>> vals(N);
for (int i = 0; i < M; i++) {
vals[P[i]].push_back(Y[i]);
}
for (int i = 0; i < N; i++) {
sort(vals[i].begin(), vals[i].end());
}
for (int i = 0; i < M; i++) {
int v = P[i];
printf("%06d", v + 1);
int id =
lower_bound(vals[v].begin(), vals[v].end(), Y[i]) - vals[v].begin();
printf("%06d\n", id + 1);
}
} | replace | 22 | 23 | 22 | 23 | -11 | |
p03221 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <math.h>
#include <string.h>
#include <vector>
typedef long long ll;
using namespace std;
ll Mod = 1e9 + 7;
int main() {
int N, M;
vector<int> tmp[N + 1];
int P[100000], Y[100000];
cin >> N >> M;
for (int i = 0; i < M; i++) {
cin >> P[i] >> Y[i];
tmp[P[i]].push_back(Y[i]);
}
for (int i = 0; i < N; i++) {
sort(tmp[i + 1].begin(), tmp[i + 1].end());
}
for (int i = 0; i < M; i++) {
printf("%012lld\n",
ll(P[i]) * 1000000 +
int(lower_bound(tmp[P[i]].begin(), tmp[P[i]].end(), Y[i]) -
tmp[P[i]].begin()) +
1);
}
return 0;
} | #include <algorithm>
#include <iostream>
#include <math.h>
#include <string.h>
#include <vector>
typedef long long ll;
using namespace std;
ll Mod = 1e9 + 7;
int main() {
int N, M;
vector<int> tmp[100001];
int P[100000], Y[100000];
cin >> N >> M;
for (int i = 0; i < M; i++) {
cin >> P[i] >> Y[i];
tmp[P[i]].push_back(Y[i]);
}
for (int i = 0; i < N; i++) {
sort(tmp[i + 1].begin(), tmp[i + 1].end());
}
for (int i = 0; i < M; i++) {
printf("%012lld\n",
ll(P[i]) * 1000000 +
int(lower_bound(tmp[P[i]].begin(), tmp[P[i]].end(), Y[i]) -
tmp[P[i]].begin()) +
1);
}
return 0;
} | replace | 12 | 13 | 12 | 13 | -11 | |
p03221 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define exrep(i, a, b) for (ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
int main() {
ll n, m;
cin >> n >> m;
vector<vector<pair<ll, ll>>> v(
n +
1); // v[i][j] : 県i(iは1-index)に属する市の中でj番目に早く誕生した市の
// (誕生年, 市の番号)
exrep(i, 1, m) {
ll p, y;
cin >> p >> y;
v[p].pb(make_pair(y, i));
}
exrep(i, 1, n) {
if (v[i].size() == 0) {
continue;
}
sort(all(v[i]));
}
vector<pair<ll, ll>> w(
n +
1); // w[i] : 市i(iは1-index)の (属する県の番号, その県の中で誕生した順番)
exrep(i, 1, n) {
rep(j, v[i].size()) {
ll k = v[i][j].second;
w[k] = make_pair(i, j + 1);
}
}
exrep(i, 1, m) {
ll A = w[i].first;
ll B = w[i].second;
printf("%06lld", A);
printf("%06lld\n", B);
}
re0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define exrep(i, a, b) for (ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
int main() {
ll n, m;
cin >> n >> m;
vector<vector<pair<ll, ll>>> v(
n +
1); // v[i][j] : 県i(iは1-index)に属する市の中でj番目に早く誕生した市の
// (誕生年, 市の番号)
exrep(i, 1, m) {
ll p, y;
cin >> p >> y;
v[p].pb(make_pair(y, i));
}
exrep(i, 1, n) {
if (v[i].size() == 0) {
continue;
}
sort(all(v[i]));
}
vector<pair<ll, ll>> w(
m +
1); // w[i] : 市i(iは1-index)の (属する県の番号, その県の中で誕生した順番)
exrep(i, 1, n) {
rep(j, v[i].size()) {
ll k = v[i][j].second;
w[k] = make_pair(i, j + 1);
}
}
exrep(i, 1, m) {
ll A = w[i].first;
ll B = w[i].second;
printf("%06lld", A);
printf("%06lld\n", B);
}
re0;
} | replace | 54 | 55 | 54 | 55 | -6 | Fatal glibc error: malloc assertion failure in sysmalloc: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)
|
p03221 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, n) for (int i = 1; i < (int)(n); ++i)
using namespace std;
int digit(int x) {
int ans = 0;
while (x > 0) {
++ans;
x /= 10;
}
return ans;
}
int main() {
int N, M;
cin >> N >> M;
vector<vector<pair<int, int>>> SHI(M);
vector<int> P(M);
rep(i, M) {
int p, Y;
cin >> p >> Y;
P[i] = p;
SHI[p - 1].push_back(make_pair(Y, i));
}
rep(i, N) sort(SHI[i].begin(), SHI[i].end());
vector<int> last(M);
rep(i, N) rep(j, SHI[i].size()) { last[SHI[i][j].second] = j + 1; }
rep(i, M) {
rep(j, 6 - digit(P[i])) cout << 0;
cout << P[i];
rep(j, 6 - digit(last[i])) cout << 0;
cout << last[i] << endl;
}
return 0;
}
| #include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, n) for (int i = 1; i < (int)(n); ++i)
using namespace std;
int digit(int x) {
int ans = 0;
while (x > 0) {
++ans;
x /= 10;
}
return ans;
}
int main() {
int N, M;
cin >> N >> M;
vector<vector<pair<int, int>>> SHI(N);
vector<int> P(M);
rep(i, M) {
int p, Y;
cin >> p >> Y;
P[i] = p;
SHI[p - 1].push_back(make_pair(Y, i));
}
rep(i, N) sort(SHI[i].begin(), SHI[i].end());
vector<int> last(M);
rep(i, N) rep(j, SHI[i].size()) { last[SHI[i][j].second] = j + 1; }
rep(i, M) {
rep(j, 6 - digit(P[i])) cout << 0;
cout << P[i];
rep(j, 6 - digit(last[i])) cout << 0;
cout << last[i] << endl;
}
return 0;
}
| replace | 20 | 21 | 20 | 21 | 0 | |
p03221 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#include <iostream>
using namespace std;
using ll = int64_t;
#define rep(i, n) for (int i = 0; i < ((int)(n)); i++) // 0-indexed昇順
int main() {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
std::cout << std::fixed << std::setprecision(15);
int N, M;
scanf("%d%d", &N, &M);
int PREF[100001];
int YEAR[100001];
vector<int> MAP[100001];
rep(i, M) {
scanf("%d%d", &PREF[i], &YEAR[i]);
MAP[PREF[i]].push_back(YEAR[i]);
}
rep(i, N) { sort(MAP[i + 1].begin(), MAP[i + 1].end()); }
rep(i, M) {
int P, Y;
P = PREF[i];
Y = YEAR[i];
auto B = MAP[P].begin();
auto j = find(B, end(MAP[P]), Y);
printf("%012ld\n", (ll)P * 1000000 + (int)(j - B) + 1);
}
}
| #include <bits/stdc++.h>
#include <iostream>
using namespace std;
using ll = int64_t;
#define rep(i, n) for (int i = 0; i < ((int)(n)); i++) // 0-indexed昇順
int main() {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
std::cout << std::fixed << std::setprecision(15);
int N, M;
scanf("%d%d", &N, &M);
int PREF[100001];
int YEAR[100001];
vector<int> MAP[100001];
rep(i, M) {
scanf("%d%d", &PREF[i], &YEAR[i]);
MAP[PREF[i]].push_back(YEAR[i]);
}
rep(i, N) { sort(MAP[i + 1].begin(), MAP[i + 1].end()); }
rep(i, M) {
int P, Y;
P = PREF[i];
Y = YEAR[i];
auto B = MAP[P].begin();
auto j = lower_bound(B, end(MAP[P]), Y);
printf("%012ld\n", (ll)P * 1000000 + (int)(j - B) + 1);
}
} | replace | 26 | 27 | 26 | 27 | TLE | |
p03221 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
int main() {
int N, M;
cin >> N >> M;
vector<int> P(N + 1), city(N + 1);
vector<vector<int>> Ms(N + 1, vector<int>());
for (int i = 1; i <= M; i++) {
int x, y;
cin >> x >> y;
P[i] = x;
city[i] = y;
Ms[x].push_back(y);
}
for (int i = 1; i <= N; i++) {
sort(Ms[i].begin(), Ms[i].end());
}
for (int i = 1; i <= M; i++) {
cout << setfill('0') << setw(6) << right << P[i];
auto ite = lower_bound(Ms[P[i]].begin(), Ms[P[i]].end(), city[i]);
cout << setfill('0') << setw(6) << right << ite - Ms[P[i]].begin() + 1;
cout << endl;
}
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
int main() {
int N, M;
cin >> N >> M;
vector<int> P(M + 1), city(M + 1);
vector<vector<int>> Ms(N + 1, vector<int>());
for (int i = 1; i <= M; i++) {
int x, y;
cin >> x >> y;
P[i] = x;
city[i] = y;
Ms[x].push_back(y);
}
for (int i = 1; i <= N; i++) {
sort(Ms[i].begin(), Ms[i].end());
}
for (int i = 1; i <= M; i++) {
cout << setfill('0') << setw(6) << right << P[i];
auto ite = lower_bound(Ms[P[i]].begin(), Ms[P[i]].end(), city[i]);
cout << setfill('0') << setw(6) << right << ite - Ms[P[i]].begin() + 1;
cout << endl;
}
}
| replace | 8 | 9 | 8 | 9 | 0 | |
p03221 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
bool cmp(pair<int, int> a, pair<int, int> b) { return a.first < b.first; }
int output(int i) {
if (i < 10) {
cout << "00000" << i;
} else if (i < 100) {
cout << "0000" << i;
} else if (i < 1000) {
cout << "000" << i;
} else if (i < 10000) {
cout << "00" << i;
} else if (i < 100000) {
cout << "0" << i;
} else {
cout << i;
}
return 0;
}
int main() {
int n, m;
cin >> n >> m;
vector<vector<pair<int, int>>> simo(n + 1);
vector<int> pre(n + 1);
vector<int> ban(n + 1);
for (int i = 1; i <= m; i++) {
int p, y;
cin >> p >> y;
simo[p].push_back(make_pair(y, i));
pre[i] = p;
}
for (int i = 1; i <= n; i++) {
sort(simo[i].begin(), simo[i].end(), cmp);
}
for (int i = 1; i <= n; i++) {
for (int j = 0; j < simo[i].size(); j++) {
ban[simo[i][j].second] = j + 1;
}
}
for (int i = 1; i <= m; i++) {
output(pre[i]);
output(ban[i]);
cout << endl;
}
} | #include <algorithm>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
bool cmp(pair<int, int> a, pair<int, int> b) { return a.first < b.first; }
int output(int i) {
if (i < 10) {
cout << "00000" << i;
} else if (i < 100) {
cout << "0000" << i;
} else if (i < 1000) {
cout << "000" << i;
} else if (i < 10000) {
cout << "00" << i;
} else if (i < 100000) {
cout << "0" << i;
} else {
cout << i;
}
return 0;
}
int main() {
int n, m;
cin >> n >> m;
vector<vector<pair<int, int>>> simo(n + 1);
vector<int> pre(m + 1);
vector<int> ban(m + 1);
for (int i = 1; i <= m; i++) {
int p, y;
cin >> p >> y;
simo[p].push_back(make_pair(y, i));
pre[i] = p;
}
for (int i = 1; i <= n; i++) {
sort(simo[i].begin(), simo[i].end(), cmp);
}
for (int i = 1; i <= n; i++) {
for (int j = 0; j < simo[i].size(); j++) {
ban[simo[i][j].second] = j + 1;
}
}
for (int i = 1; i <= m; i++) {
output(pre[i]);
output(ban[i]);
cout << endl;
}
} | replace | 30 | 32 | 30 | 32 | 0 | |
p03221 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <type_traits>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define drrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))
using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using ld = long double;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << "(" << p.first << "," << p.second << ")";
return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
os << "{";
rep(i, (int)v.size()) {
if (i)
os << ",";
os << v[i];
}
os << "}";
return os;
}
template <typename T, size_t S> void printArray(const T (&array)[S]) {
for (auto val : array)
std::cout << val << ", ";
std::cout << "\n";
}
const int MOD = 1'000'000'000 + 7;
const int INF = 1'000'000'000 + 5;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(16);
int n, m;
std::cin >> n >> m;
vi p(n), y(m);
vvi vvp(n);
rep(i, m) {
std::cin >> p[i] >> y[i];
p[i]--;
vvp[p[i]].pb(y[i]);
}
rep(i, n) { sort(rng(vvp[i])); }
rep(i, m) {
auto it = lower_bound(rng(vvp[p[i]]), y[i]) - vvp[p[i]].begin();
printf("%06d%06d\n", p[i] + 1, (int)it + 1);
}
}
| #include <bits/stdc++.h>
#include <type_traits>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define drrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))
using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using ld = long double;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << "(" << p.first << "," << p.second << ")";
return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
os << "{";
rep(i, (int)v.size()) {
if (i)
os << ",";
os << v[i];
}
os << "}";
return os;
}
template <typename T, size_t S> void printArray(const T (&array)[S]) {
for (auto val : array)
std::cout << val << ", ";
std::cout << "\n";
}
const int MOD = 1'000'000'000 + 7;
const int INF = 1'000'000'000 + 5;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(16);
int n, m;
std::cin >> n >> m;
vi p(m), y(m);
vvi vvp(n);
rep(i, m) {
std::cin >> p[i] >> y[i];
p[i]--;
vvp[p[i]].pb(y[i]);
}
rep(i, n) { sort(rng(vvp[i])); }
rep(i, m) {
auto it = lower_bound(rng(vvp[p[i]]), y[i]) - vvp[p[i]].begin();
printf("%06d%06d\n", p[i] + 1, (int)it + 1);
}
}
| replace | 58 | 59 | 58 | 59 | 0 | |
p03221 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long int i = 0; i < n; ++i)
typedef long long int ll;
string encode(int i) {
string num = to_string(i);
while (num.size() < 6) {
num = '0' + num;
}
return num;
}
int main() {
int n, m;
cin >> n >> m;
vector<pair<int, int>> s(m);
vector<int> p[n + 1];
rep(i, m) {
cin >> s[i].first >> s[i].second;
p[s[i].first].push_back(s[i].second);
}
rep(i, m) { sort(p[i].begin(), p[i].end()); }
for (int i = 0; i < m; i++) {
auto it =
lower_bound(p[s[i].first].begin(), p[s[i].first].end(), s[i].second);
int t = distance(p[s[i].first].begin(), it);
string ans = encode(s[i].first) + encode(t + 1);
cout << ans << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long int i = 0; i < n; ++i)
typedef long long int ll;
string encode(int i) {
string num = to_string(i);
while (num.size() < 6) {
num = '0' + num;
}
return num;
}
int main() {
int n, m;
cin >> n >> m;
vector<pair<int, int>> s(m);
vector<int> p[n + 1];
rep(i, m) {
cin >> s[i].first >> s[i].second;
p[s[i].first].push_back(s[i].second);
}
rep(i, n + 1) { sort(p[i].begin(), p[i].end()); }
for (int i = 0; i < m; i++) {
auto it =
lower_bound(p[s[i].first].begin(), p[s[i].first].end(), s[i].second);
int t = distance(p[s[i].first].begin(), it);
string ans = encode(s[i].first) + encode(t + 1);
cout << ans << endl;
}
return 0;
} | replace | 24 | 25 | 24 | 25 | 0 | |
p03221 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;
ll gcd(ll n, ll m) {
ll tmp;
while (m != 0) {
tmp = n % m;
n = m;
m = tmp;
}
return n;
}
ll lcm(ll n, ll m) {
return abs(n * m) / gcd(n, m); // gl=xy
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
using namespace std;
// ここから
using P = pair<int, int>;
void solve() {
int n, m;
cin >> n >> m;
vector<vector<P>> v(n);
rep(i, m) {
int p, y;
cin >> p >> y;
p--;
v[p].eb(y, i);
}
vector<P> ans(m);
rep(i, m) {
if (v[i].size() > 1)
sort(v[i].begin(), v[i].end());
rep(j, v[i].size()) { ans[v[i][j].second] = P{i + 1, j + 1}; }
}
rep(i, m) {
string s = to_string(ans[i].first), t = to_string(ans[i].second);
while (s.size() < 6)
s = "0" + s;
while (t.size() < 6)
t = "0" + t;
cout << s << t << endl;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(15);
solve();
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;
ll gcd(ll n, ll m) {
ll tmp;
while (m != 0) {
tmp = n % m;
n = m;
m = tmp;
}
return n;
}
ll lcm(ll n, ll m) {
return abs(n * m) / gcd(n, m); // gl=xy
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
using namespace std;
// ここから
using P = pair<int, int>;
void solve() {
int n, m;
cin >> n >> m;
vector<vector<P>> v(n);
rep(i, m) {
int p, y;
cin >> p >> y;
p--;
v[p].eb(y, i);
}
vector<P> ans(m);
rep(i, n) {
if (v[i].size() > 1)
sort(v[i].begin(), v[i].end());
rep(j, v[i].size()) { ans[v[i][j].second] = P{i + 1, j + 1}; }
}
rep(i, m) {
string s = to_string(ans[i].first), t = to_string(ans[i].second);
while (s.size() < 6)
s = "0" + s;
while (t.size() < 6)
t = "0" + t;
cout << s << t << endl;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(15);
solve();
return 0;
}
| replace | 76 | 77 | 76 | 77 | -11 | |
p03221 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <vector>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;
int main() {
int N, M;
cin >> N >> M;
int P[M], Y[M];
rep(i, M) cin >> P[i] >> Y[i];
vector<int> C[N + 1];
rep(i, M) C[P[i]].push_back(Y[i]);
rep(i, N + 1) sort(C[i].begin(), C[i].end());
rep(i, M) {
cout << setfill('0') << setw(6) << P[i];
int id = find(C[P[i]].begin(), C[P[i]].end(), Y[i]) - C[P[i]].begin() + 1;
cout << setfill('0') << setw(6) << id << endl;
}
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <vector>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;
int main() {
int N, M;
cin >> N >> M;
int P[M], Y[M];
rep(i, M) cin >> P[i] >> Y[i];
vector<int> C[N + 1];
rep(i, M) C[P[i]].push_back(Y[i]);
rep(i, N + 1) sort(C[i].begin(), C[i].end());
rep(i, M) {
cout << setfill('0') << setw(6) << P[i];
int id =
lower_bound(C[P[i]].begin(), C[P[i]].end(), Y[i]) - C[P[i]].begin() + 1;
cout << setfill('0') << setw(6) << id << endl;
}
return 0;
} | replace | 25 | 26 | 25 | 27 | TLE | |
p03221 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define p(s) std::cout << s;
#define pl(s) std::cout << s << endl;
#define printIf(j, s1, s2) cout << (j ? s1 : s2) << endl;
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;
#define all(v) v.begin(), v.end()
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
typedef long long int ll;
const ll longinf = 1LL << 60;
vector<int> g[100005];
int main() {
int N, M;
cin >> N >> M;
vector<int> P(M), Y(M);
REP(i, M) {
cin >> P[i] >> Y[i];
g[P[i]].push_back(Y[i]);
}
REP(i, M) sort(all(g[P[i]]));
REP(i, M) {
int d = (upper_bound(all(g[P[i]]), Y[i]) - g[P[i]].begin());
printf("%06d%06d\n", P[i], d);
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define p(s) std::cout << s;
#define pl(s) std::cout << s << endl;
#define printIf(j, s1, s2) cout << (j ? s1 : s2) << endl;
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;
#define all(v) v.begin(), v.end()
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
typedef long long int ll;
const ll longinf = 1LL << 60;
vector<int> g[100005];
int main() {
int N, M;
cin >> N >> M;
vector<int> P(M), Y(M);
REP(i, M) {
cin >> P[i] >> Y[i];
g[P[i]].push_back(Y[i]);
}
REP(i, N) if (!g[i + 1].empty()) sort(all(g[i + 1]));
REP(i, M) {
int d = (upper_bound(all(g[P[i]]), Y[i]) - g[P[i]].begin());
printf("%06d%06d\n", P[i], d);
}
return 0;
}
| replace | 41 | 42 | 41 | 42 | TLE | |
p03221 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void) {
int n, m;
cin >> n >> m;
vector<pair<int, int>> city(m);
vector<vector<int>> a(n);
for (int i = 0; i < m; i++) {
int p, y;
cin >> p >> y;
city[i].first = p;
city[i].second = y;
a[p - 1].push_back(y);
}
for (int i = 0; i < a.size(); i++) {
sort(a[i].begin(), a[i].end());
}
for (int i = 0; i < m; i++) {
for (int j = 0; j < a[city[i].first - 1].size(); j++) {
// ここを2分にする?
if (city[i].second == a[city[i].first - 1][j]) {
city[i].second = j + 1;
}
}
}
// 6桁にする
vector<string> ans(m);
for (int i = 0; i < m; i++) {
ans[i] = "000000000000";
int at = city[i].first;
string s_at = to_string(at);
int year = city[i].second;
string s_year = to_string(year);
ans[i].replace(6 - s_at.size(), s_at.size(), s_at);
ans[i].replace(12 - s_year.size(), s_year.size(), s_year);
cout << ans[i] << endl;
;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void) {
int n, m;
cin >> n >> m;
vector<pair<int, int>> city(m);
vector<vector<int>> a(n);
for (int i = 0; i < m; i++) {
int p, y;
cin >> p >> y;
city[i].first = p;
city[i].second = y;
a[p - 1].push_back(y);
}
for (int i = 0; i < a.size(); i++) {
sort(a[i].begin(), a[i].end());
}
for (int i = 0; i < m; i++) {
int now_f = city[i].first - 1; // 探す場所
int now_s = city[i].second; // 探したいもの
auto Iter1 = upper_bound(a[now_f].begin(), a[now_f].end(), now_s);
city[i].second = Iter1 - a[now_f].begin();
// for(int j=0;j<a[city[i].first-1].size();j++){
// //ここを2分にする?
// if(city[i].second==a[city[i].first-1][j]){
// city[i].second = j+1;
// }
// }
}
// 6桁にする
vector<string> ans(m);
for (int i = 0; i < m; i++) {
ans[i] = "000000000000";
int at = city[i].first;
string s_at = to_string(at);
int year = city[i].second;
string s_year = to_string(year);
ans[i].replace(6 - s_at.size(), s_at.size(), s_at);
ans[i].replace(12 - s_year.size(), s_year.size(), s_year);
cout << ans[i] << endl;
;
}
return 0;
} | replace | 20 | 26 | 20 | 30 | TLE | |
p03221 | C++ | Runtime Error | #define FOR(i, begin, end) for (int i = (begin); i < (end); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(), a.end())
#define SORTD(a) sort(a.rbegin(), a.rend());
#define ll long long
#define INF 1000000000000000000
#define INT_MAX 2147483647
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <ios>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <utility>
#include <vector>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
int P[100001], Y[100001];
vector<int> py[100001];
REP(i, M) {
cin >> P[i] >> Y[i];
py[P[i]].push_back(Y[i]);
}
REP(i, N + 1) { SORT(py[i + 1]); }
REP(i, M) {
cout << setfill('0') << setw(6) << right << P[i];
cout << setfill('0') << setw(6) << right
<< int(lower_bound(py[P[i]].begin(), py[P[i]].end(), Y[i]) -
py[P[i]].begin()) +
1
<< endl;
}
}
| #define FOR(i, begin, end) for (int i = (begin); i < (end); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(), a.end())
#define SORTD(a) sort(a.rbegin(), a.rend());
#define ll long long
#define INF 1000000000000000000
#define INT_MAX 2147483647
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <ios>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <utility>
#include <vector>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
int P[100001], Y[100001];
vector<int> py[100001];
REP(i, M) {
cin >> P[i] >> Y[i];
py[P[i]].push_back(Y[i]);
}
REP(i, N + 1) { SORT(py[i]); }
REP(i, M) {
cout << setfill('0') << setw(6) << right << P[i];
cout << setfill('0') << setw(6) << right
<< int(lower_bound(py[P[i]].begin(), py[P[i]].end(), Y[i]) -
py[P[i]].begin()) +
1
<< endl;
}
}
| replace | 33 | 34 | 33 | 34 | 0 | |
p03221 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define show(a, n) \
rep(i, n) { cout << a[i] << ' '; } \
cout << endl;
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;
const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;
void print_num(int n) {
if (n < 10)
cout << "00000" << n;
else if (n < 100)
cout << "0000" << n;
else if (n < 1000)
cout << "000" << n;
else if (n < 10000)
cout << "00" << n;
else if (n < 100000)
cout << "0" << n;
else
cout << n;
}
int main() {
int n, m;
cin >> n >> m;
int p[N], y[N];
pii yp[N];
rep(i, m) {
cin >> p[i] >> y[i];
yp[i] = pii(y[i], p[i]);
}
sort(yp, yp + m);
int pc[N]; // pref to count
rep(i, N) pc[i] = 0;
int yo[N]; // year to order
rep(i, m) {
int ty = yp[i].first;
int tp = yp[i].second;
pc[tp]++;
yo[ty] = pc[tp];
}
rep(i, m) {
print_num(p[i]);
print_num(yo[y[i]]);
cout << endl;
}
}
| #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define show(a, n) \
rep(i, n) { cout << a[i] << ' '; } \
cout << endl;
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;
const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;
void print_num(int n) {
if (n < 10)
cout << "00000" << n;
else if (n < 100)
cout << "0000" << n;
else if (n < 1000)
cout << "000" << n;
else if (n < 10000)
cout << "00" << n;
else if (n < 100000)
cout << "0" << n;
else
cout << n;
}
int main() {
int n, m;
cin >> n >> m;
int p[N], y[N];
pii yp[N];
rep(i, m) {
cin >> p[i] >> y[i];
yp[i] = pii(y[i], p[i]);
}
sort(yp, yp + m);
int pc[N]; // pref to count
rep(i, N) pc[i] = 0;
map<int, int> yo;
rep(i, m) {
int ty = yp[i].first;
int tp = yp[i].second;
pc[tp]++;
yo[ty] = pc[tp];
}
rep(i, m) {
print_num(p[i]);
print_num(yo[y[i]]);
cout << endl;
}
}
| replace | 61 | 62 | 61 | 62 | 0 | |
p03221 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int N, M;
int *P, *Y;
std::vector<int> *yd;
cin >> N >> M;
yd = new std::vector<int>[N];
P = new int[M];
Y = new int[M];
for (int i = 0; i < M; i++) {
cin >> P[i] >> Y[i];
yd[P[i] - 1].push_back(Y[i]);
}
for (int i = 0; i < N; i++) {
sort(yd[i].begin(), yd[i].end());
}
for (int i = 0; i < M; i++) {
int rank = 0;
for (int j = 0; j < yd[P[i] - 1].size(); j++) {
if (yd[P[i] - 1][j] == Y[i]) {
rank = j + 1;
break;
}
}
printf("%06d%06d\n", P[i], rank);
}
return 0;
} | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int N, M;
int *P, *Y;
std::vector<int> *yd;
cin >> N >> M;
yd = new std::vector<int>[N];
P = new int[M];
Y = new int[M];
for (int i = 0; i < M; i++) {
cin >> P[i] >> Y[i];
yd[P[i] - 1].push_back(Y[i]);
}
for (int i = 0; i < N; i++) {
sort(yd[i].begin(), yd[i].end());
}
for (int i = 0; i < M; i++) {
int index = P[i] - 1;
int rank = int(lower_bound(yd[index].begin(), yd[index].end(), Y[i]) -
yd[index].begin()) +
1;
printf("%06d%06d\n", P[i], rank);
}
return 0;
} | replace | 25 | 32 | 25 | 29 | TLE | |
p03221 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#include <cctype>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) (v).begin(), (v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int, int>
int main() {
int N, M;
cin >> N >> M;
int P[M], Y[M];
unordered_map<int, vector<int>> YM;
rep(i, M) {
cin >> P[i] >> Y[i];
YM[P[i]].push_back(Y[i]);
}
// rep(i,N+1) sort(all(YM.at(i)));
rep(i, M) { sort(all(YM.at(P[i]))); }
rep(i, M) {
auto x = lower_bound(all(YM.at(P[i])), Y[i]) - YM.at(P[i]).begin();
printf("%06d", P[i]);
printf("%06d\n", int(x) + 1);
}
return 0;
} | #include <bits/stdc++.h>
#include <cctype>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) (v).begin(), (v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int, int>
int main() {
int N, M;
cin >> N >> M;
int P[M], Y[M];
unordered_map<int, vector<int>> YM;
rep(i, M) {
cin >> P[i] >> Y[i];
YM[P[i]].push_back(Y[i]);
}
// rep(i,N+1) sort(all(YM.at(i)));
for (auto i = YM.begin(); i != YM.end(); i++) {
sort(all(i->second));
}
rep(i, M) {
auto x = lower_bound(all(YM.at(P[i])), Y[i]) - YM.at(P[i]).begin();
printf("%06d", P[i]);
printf("%06d\n", int(x) + 1);
}
return 0;
} | replace | 22 | 23 | 22 | 25 | TLE | |
p03221 | C++ | Runtime Error | // ref: https://drken1215.hatenablog.com/entry/2019/03/21/234900
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;
//---
template <typename T> inline void print(const T &rhs) {
std::cout << " = " << rhs << std::endl;
}
template <typename T> inline void print(const std::vector<T> &rhs) {
std::cout << " = [ ";
for (uint i = 0; i < rhs.size(); ++i) {
std::cout << rhs[i] << ' ';
}
std::cout << "]" << std::endl;
}
template <typename T>
inline void print(const std::vector<std::vector<T>> &rhs) {
std::cout << " = " << std::endl;
std::cout << "[[ ";
for (uint p = 0; p < rhs.size(); ++p) {
if (p != 0) {
std::cout << " [ ";
}
for (uint q = 0; q < rhs[p].size(); ++q) {
std::cout << rhs[p][q] << ' ';
}
if (p != rhs.size() - 1) {
std::cout << "]" << std::endl;
}
}
std::cout << "]]" << std::endl;
}
template <typename TL, typename TR>
inline void print(const std::vector<std::pair<TR, TL>> &rhs) {
std::cout << " = [";
uint i = 0;
for (; i < rhs.size() - 1; ++i) {
std::cout << "[f: " << rhs[i].first << ", s: " << rhs[i].second << "], ";
}
std::cout << "[f: " << rhs[i].first << ", s: " << rhs[i].second << "]]"
<< endl;
}
#define printn(var) \
{ \
printf("%s", #var); \
print(var); \
}
#define printn_all(var) \
{ \
printf("%s(%d): ", __func__, __LINE__); \
printf("%s", #var); \
print(var); \
}
//---
int main() {
// ios_base::sync_with_stdio(false);
// cin.tie(NULL);
uint N, M;
cin >> N >> M;
vector<int> vP(N), vY(N);
vector<vector<int>> vvPY(N);
for (uint i = 0; i < M; ++i) {
int p, y;
cin >> p >> y;
--p;
vP[i] = p;
vY[i] = y;
vvPY[p].push_back(y);
}
for (uint pi = 0; pi < vvPY.size(); ++pi) {
sort(vvPY[pi].begin(), vvPY[pi].end());
vvPY[pi].erase(unique(vvPY[pi].begin(), vvPY[pi].end()), vvPY[pi].end());
}
for (uint i = 0; i < M; ++i) {
int pi = vP[i];
int idx =
lower_bound(vvPY[pi].begin(), vvPY[pi].end(), vY[i]) - vvPY[pi].begin();
printf("%06d%06d\n", pi + 1, idx + 1);
}
return 0;
}
| // ref: https://drken1215.hatenablog.com/entry/2019/03/21/234900
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;
//---
template <typename T> inline void print(const T &rhs) {
std::cout << " = " << rhs << std::endl;
}
template <typename T> inline void print(const std::vector<T> &rhs) {
std::cout << " = [ ";
for (uint i = 0; i < rhs.size(); ++i) {
std::cout << rhs[i] << ' ';
}
std::cout << "]" << std::endl;
}
template <typename T>
inline void print(const std::vector<std::vector<T>> &rhs) {
std::cout << " = " << std::endl;
std::cout << "[[ ";
for (uint p = 0; p < rhs.size(); ++p) {
if (p != 0) {
std::cout << " [ ";
}
for (uint q = 0; q < rhs[p].size(); ++q) {
std::cout << rhs[p][q] << ' ';
}
if (p != rhs.size() - 1) {
std::cout << "]" << std::endl;
}
}
std::cout << "]]" << std::endl;
}
template <typename TL, typename TR>
inline void print(const std::vector<std::pair<TR, TL>> &rhs) {
std::cout << " = [";
uint i = 0;
for (; i < rhs.size() - 1; ++i) {
std::cout << "[f: " << rhs[i].first << ", s: " << rhs[i].second << "], ";
}
std::cout << "[f: " << rhs[i].first << ", s: " << rhs[i].second << "]]"
<< endl;
}
#define printn(var) \
{ \
printf("%s", #var); \
print(var); \
}
#define printn_all(var) \
{ \
printf("%s(%d): ", __func__, __LINE__); \
printf("%s", #var); \
print(var); \
}
//---
int main() {
// ios_base::sync_with_stdio(false);
// cin.tie(NULL);
uint N, M;
cin >> N >> M;
vector<int> vP(M), vY(M);
vector<vector<int>> vvPY(N);
for (uint i = 0; i < M; ++i) {
int p, y;
cin >> p >> y;
--p;
vP[i] = p;
vY[i] = y;
vvPY[p].push_back(y);
}
for (uint pi = 0; pi < vvPY.size(); ++pi) {
sort(vvPY[pi].begin(), vvPY[pi].end());
vvPY[pi].erase(unique(vvPY[pi].begin(), vvPY[pi].end()), vvPY[pi].end());
}
for (uint i = 0; i < M; ++i) {
int pi = vP[i];
int idx =
lower_bound(vvPY[pi].begin(), vvPY[pi].end(), vY[i]) - vvPY[pi].begin();
printf("%06d%06d\n", pi + 1, idx + 1);
}
return 0;
}
| replace | 69 | 70 | 69 | 70 | 0 | |
p03221 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
void solve() {
int N, M;
cin >> N >> M;
vector<int> P(M), Y(M);
vector<vector<int>> yd(M + 1, vector<int>(0));
for (int i = 0; i < M; i++) {
cin >> P[i] >> Y[i];
yd[P[i]].push_back(Y[i]);
}
for (int i = 0; i < N; i++) {
sort(yd[i + 1].begin(), yd[i + 1].end());
}
for (int i = 0; i < M; i++) {
cout << setfill('0') << setw(6) << P[i] << setfill('0') << setw(6)
<< (int)(lower_bound(yd[P[i]].begin(), yd[P[i]].end(), Y[i]) -
yd[P[i]].begin()) +
1
<< endl;
}
}
int main() {
solve();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
void solve() {
int N, M;
cin >> N >> M;
vector<int> P(M), Y(M);
vector<vector<int>> yd(N + 1, vector<int>(0));
for (int i = 0; i < M; i++) {
cin >> P[i] >> Y[i];
yd[P[i]].push_back(Y[i]);
}
for (int i = 0; i < N; i++) {
sort(yd[i + 1].begin(), yd[i + 1].end());
}
for (int i = 0; i < M; i++) {
cout << setfill('0') << setw(6) << P[i] << setfill('0') << setw(6)
<< (int)(lower_bound(yd[P[i]].begin(), yd[P[i]].end(), Y[i]) -
yd[P[i]].begin()) +
1
<< endl;
}
}
int main() {
solve();
return 0;
} | replace | 8 | 9 | 8 | 9 | 0 | |
p03221 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int p[maxn], y[maxn];
vector<int> a[maxn];
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 0; i < m; i++) {
scanf("%d%d", &p[i], &y[i]);
a[p[i]].push_back(y[i]);
sort(a[p[i]].begin(), a[p[i]].end());
}
for (int i = 0; i < m; i++) {
int pos =
lower_bound(a[p[i]].begin(), a[p[i]].end(), y[i]) - a[p[i]].begin();
printf("%06d%06d\n", p[i], pos + 1);
}
}
| #include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int p[maxn], y[maxn];
vector<int> a[maxn];
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 0; i < m; i++) {
scanf("%d%d", &p[i], &y[i]);
a[p[i]].push_back(y[i]);
}
for (int i = 1; i <= n; i++) {
if (a[i].size() > 0)
sort(a[i].begin(), a[i].end());
}
for (int i = 0; i < m; i++) {
int pos =
lower_bound(a[p[i]].begin(), a[p[i]].end(), y[i]) - a[p[i]].begin();
printf("%06d%06d\n", p[i], pos + 1);
}
}
| replace | 11 | 12 | 11 | 15 | TLE | |
p03221 | C++ | Runtime Error | /*
-ensure correct output format
-ensure printing required output
-reread the problem statement
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<ll, pair<ll, ll>> plll;
#define fastread() (ios_base::sync_with_stdio(false), cin.tie(NULL));
#define vll(v) v.begin(), v.end()
#define all(x) x.rbegin(), x.rend()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define F first
#define S second
#define in freopen("input.txt", "r", stdin)
#define out freopen("output.txt", "w", stdout)
#define minheap int, vector<int>, greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x) (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) \
((ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') || \
(ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U'))
#define bug cout << "BUG" << endl;
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const double PI = 3.141592653589793238463;
bool compare(const pair<ll, ll> &a, const pair<ll, ll> &b) {
return (a.first > b.first);
}
ll lcm(ll a, ll b) {
if (a == 0 || b == 0)
return 0;
return a / __gcd(a, b) * b;
}
void input(ll ara[], ll n) {
for (ll i = 0; i < n; i++)
cin >> ara[i];
}
void print(ll ara[], ll n) {
for (ll i = 0; i < n; i++)
cout << ara[i] << " ";
cout << endl;
}
vector<pll> adj[Max];
int main() {
fastread();
ll i, j, n, m, p, a, sum = 0, k, b, c, d, cnt = 0, q, l, r;
bool flag = false;
string str;
cin >> n >> m;
vector<pll> v;
pair<string, string> Ans[n + 2];
for (i = 0; i < m; i++) {
cin >> a >> b;
v.eb(a, b);
adj[a].eb(b, i);
d = log10(a) + 1;
string temp = to_string(a);
for (ll j = 0; j < 6 - d; j++)
temp = "0" + temp;
Ans[i].F = temp;
}
for (i = 1; i <= n; i++) {
sort(vll(adj[i]));
cnt = 1;
for (auto x : adj[i]) {
d = log10(cnt) + 1;
string temp = to_string(cnt);
;
for (j = 0; j < 6 - d; j++)
temp = "0" + temp;
Ans[x.S].S = temp;
cnt++;
}
}
for (i = 0; i < m; i++) {
cout << Ans[i].F << "" << Ans[i].S << endl;
}
}
| /*
-ensure correct output format
-ensure printing required output
-reread the problem statement
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<ll, pair<ll, ll>> plll;
#define fastread() (ios_base::sync_with_stdio(false), cin.tie(NULL));
#define vll(v) v.begin(), v.end()
#define all(x) x.rbegin(), x.rend()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define F first
#define S second
#define in freopen("input.txt", "r", stdin)
#define out freopen("output.txt", "w", stdout)
#define minheap int, vector<int>, greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x) (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) \
((ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') || \
(ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U'))
#define bug cout << "BUG" << endl;
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const double PI = 3.141592653589793238463;
bool compare(const pair<ll, ll> &a, const pair<ll, ll> &b) {
return (a.first > b.first);
}
ll lcm(ll a, ll b) {
if (a == 0 || b == 0)
return 0;
return a / __gcd(a, b) * b;
}
void input(ll ara[], ll n) {
for (ll i = 0; i < n; i++)
cin >> ara[i];
}
void print(ll ara[], ll n) {
for (ll i = 0; i < n; i++)
cout << ara[i] << " ";
cout << endl;
}
vector<pll> adj[Max];
int main() {
fastread();
ll i, j, n, m, p, a, sum = 0, k, b, c, d, cnt = 0, q, l, r;
bool flag = false;
string str;
cin >> n >> m;
vector<pll> v;
pair<string, string> Ans[m + 2];
for (i = 0; i < m; i++) {
cin >> a >> b;
v.eb(a, b);
adj[a].eb(b, i);
d = log10(a) + 1;
string temp = to_string(a);
for (ll j = 0; j < 6 - d; j++)
temp = "0" + temp;
Ans[i].F = temp;
}
for (i = 1; i <= n; i++) {
sort(vll(adj[i]));
cnt = 1;
for (auto x : adj[i]) {
d = log10(cnt) + 1;
string temp = to_string(cnt);
;
for (j = 0; j < 6 - d; j++)
temp = "0" + temp;
Ans[x.S].S = temp;
cnt++;
}
}
for (i = 0; i < m; i++) {
cout << Ans[i].F << "" << Ans[i].S << endl;
}
}
| replace | 68 | 69 | 68 | 69 | 0 | |
p03221 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
typedef unsigned int uint;
using namespace std;
int main() {
int N, M;
cin >> N >> M;
pair<pair<int, int>, int> p[N];
for (int i = 0; i < M; i++) {
cin >> p[i].first.first >> p[i].first.second;
p[i].second = i;
}
sort(p, p + M);
/*for(int i=0;i<M;i++){
cout << p[i].first.first << " ";
cout << p[i].first.second << " ";
cout << p[i].second << endl;
}*/
int id[M];
id[0] = 1;
for (int i = 1; i < M; i++) {
if (p[i].first.first != p[i - 1].first.first) {
id[i] = 1;
} else {
id[i] = id[i - 1] + 1;
}
}
pair<int, pair<int, int>> pp[M];
for (int i = 0; i < M; i++) {
pp[i].first = p[i].second;
pp[i].second.first = p[i].first.first;
pp[i].second.second = id[i];
}
sort(pp, pp + M);
for (int i = 0; i < M; i++) {
printf("%06d%06d\n", pp[i].second.first, pp[i].second.second);
}
return 0;
}
| #include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
typedef unsigned int uint;
using namespace std;
int main() {
int N, M;
cin >> N >> M;
pair<pair<int, int>, int> p[M];
for (int i = 0; i < M; i++) {
cin >> p[i].first.first >> p[i].first.second;
p[i].second = i;
}
sort(p, p + M);
/*for(int i=0;i<M;i++){
cout << p[i].first.first << " ";
cout << p[i].first.second << " ";
cout << p[i].second << endl;
}*/
int id[M];
id[0] = 1;
for (int i = 1; i < M; i++) {
if (p[i].first.first != p[i - 1].first.first) {
id[i] = 1;
} else {
id[i] = id[i - 1] + 1;
}
}
pair<int, pair<int, int>> pp[M];
for (int i = 0; i < M; i++) {
pp[i].first = p[i].second;
pp[i].second.first = p[i].first.first;
pp[i].second.second = id[i];
}
sort(pp, pp + M);
for (int i = 0; i < M; i++) {
printf("%06d%06d\n", pp[i].second.first, pp[i].second.second);
}
return 0;
} | replace | 19 | 20 | 19 | 20 | 0 | |
p03221 | C++ | Runtime Error | #include <bits/stdc++.h>
#define FOR(i, begin, end) for (int i = (begin); i < (end); i++)
#define REP(i, n) FOR(i, 0, n)
#define IFOR(i, begin, end) for (int i = (end)-1; i >= (begin); i--)
#define IREP(i, n) IFOR(i, 0, n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) \
distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;
typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;
template <typename T> void readv(vector<T> &a) { REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a) {
REP(i, a.size()) {
cin >> a[i];
a[i]--;
}
}
int add0(int n) {
int k = 0, s = 1;
while (n >= s) {
s *= 10;
k++;
}
// string S = "";
// REP(i, 6 - k) S += '0';
return 6 - k;
}
signed main() {
int N, M;
cin >> N >> M;
vec P(N), Y(N);
REP(i, M) cin >> P[i] >> Y[i];
map<int, vector<Pii>> m;
set<int> s;
REP(i, M) {
m[P[i]].push_back(Pii(Y[i], i));
s.insert(P[i]);
}
for (int n : s)
SORT(m[n]);
vec ans(M);
for (int n : s) {
REP(i, m[n].size()) ans[m[n][i].second] = i + 1;
}
REP(i, M) {
REP(k, add0(P[i])) cout << '0';
cout << P[i];
REP(k, add0(ans[i])) cout << '0';
cout << ans[i];
cout << endl;
}
return 0;
} | #include <bits/stdc++.h>
#define FOR(i, begin, end) for (int i = (begin); i < (end); i++)
#define REP(i, n) FOR(i, 0, n)
#define IFOR(i, begin, end) for (int i = (end)-1; i >= (begin); i--)
#define IREP(i, n) IFOR(i, 0, n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) \
distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;
typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;
template <typename T> void readv(vector<T> &a) { REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a) {
REP(i, a.size()) {
cin >> a[i];
a[i]--;
}
}
int add0(int n) {
int k = 0, s = 1;
while (n >= s) {
s *= 10;
k++;
}
// string S = "";
// REP(i, 6 - k) S += '0';
return 6 - k;
}
signed main() {
int N, M;
cin >> N >> M;
vec P(M), Y(M);
REP(i, M) cin >> P[i] >> Y[i];
map<int, vector<Pii>> m;
set<int> s;
REP(i, M) {
m[P[i]].push_back(Pii(Y[i], i));
s.insert(P[i]);
}
for (int n : s)
SORT(m[n]);
vec ans(M);
for (int n : s) {
REP(i, m[n].size()) ans[m[n][i].second] = i + 1;
}
REP(i, M) {
REP(k, add0(P[i])) cout << '0';
cout << P[i];
REP(k, add0(ans[i])) cout << '0';
cout << ans[i];
cout << endl;
}
return 0;
} | replace | 42 | 43 | 42 | 43 | 0 | |
p03221 | C++ | Runtime Error | #include <algorithm>
#include <chrono>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
int main(int argc, const char *argv[]) {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<vector<int>> yp(m, vector<int>(3));
vector<int> cnt(n + 1, 0);
for (int i = 0; i < m; i++) {
cin >> yp[i][0] >> yp[i][1];
yp[i][2] = i;
cnt[yp[i][0]]++;
}
sort(yp.begin(), yp.end());
map<int, string> ID;
int p = 0;
for (int i = 1; i <= n; i++) {
while (cnt[i] == 0)
i++;
string pid = to_string(i);
pid = string(6 - pid.size(), '0') + pid;
for (int j = 0; j < cnt[i]; j++) {
string xid = to_string(j + 1);
xid = string(6 - xid.size(), '0') + xid;
ID.emplace(yp[p][2], pid + xid);
p++;
}
}
for (auto &iter : ID) {
cout << iter.second << endl;
}
return 0;
}
| #include <algorithm>
#include <chrono>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
int main(int argc, const char *argv[]) {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<vector<int>> yp(m, vector<int>(3));
vector<int> cnt(n + 1, 0);
for (int i = 0; i < m; i++) {
cin >> yp[i][0] >> yp[i][1];
yp[i][2] = i;
cnt[yp[i][0]]++;
}
sort(yp.begin(), yp.end());
map<int, string> ID;
int p = 0;
for (int i = 1; i <= n; i++) {
string pid = to_string(i);
pid = string(6 - pid.size(), '0') + pid;
for (int j = 0; j < cnt[i]; j++) {
string xid = to_string(j + 1);
xid = string(6 - xid.size(), '0') + xid;
ID.emplace(yp[p][2], pid + xid);
p++;
}
}
for (auto &iter : ID) {
cout << iter.second << endl;
}
return 0;
}
| delete | 33 | 36 | 33 | 33 | 0 | |
p03221 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ll n, m;
cin >> n >> m;
ll p[m], y[m];
vector<ll> py[m * 2];
for (int i = 0; i < m; i++)
cin >> p[i] >> y[i];
for (int i = 0; i < m; i++)
py[p[i]].push_back(y[i]);
for (int i = 0; i < n; i++)
sort(py[i + 1].begin(), py[i + 1].end());
for (int i = 0; i < m; i++) {
printf("%012lld\n",
ll(p[i]) * 1000000 +
int(lower_bound(py[p[i]].begin(), py[p[i]].end(), y[i]) -
py[p[i]].begin()) +
1);
}
/* for(int i=0;i<m;i++){
printf("%lld\n",*lower_bound(py[p[i]].begin(),py[p[i]].end(),y[i]));
}*/
// for(int i=0;i<m;i++)num[y[i]]=i;
// sort(y,y+m);
/*for( vector<ll>::iterator i=begin(py);i!=end(py);++i) {
std::cout << i << std::endl;
}*/
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ll n, m;
cin >> n >> m;
ll p[m], y[m];
vector<ll> py[n + 1];
for (int i = 0; i < m; i++)
cin >> p[i] >> y[i];
for (int i = 0; i < m; i++)
py[p[i]].push_back(y[i]);
for (int i = 0; i < n; i++)
sort(py[i + 1].begin(), py[i + 1].end());
for (int i = 0; i < m; i++) {
printf("%012lld\n",
ll(p[i]) * 1000000 +
int(lower_bound(py[p[i]].begin(), py[p[i]].end(), y[i]) -
py[p[i]].begin()) +
1);
}
/* for(int i=0;i<m;i++){
printf("%lld\n",*lower_bound(py[p[i]].begin(),py[p[i]].end(),y[i]));
}*/
// for(int i=0;i<m;i++)num[y[i]]=i;
// sort(y,y+m);
/*for( vector<ll>::iterator i=begin(py);i!=end(py);++i) {
std::cout << i << std::endl;
}*/
}
| replace | 7 | 8 | 7 | 8 | 0 | |
p03221 | C++ | Runtime Error |
#include <algorithm>
#include <iostream>
#include <random>
#include <string>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;
#define NNN (10000)
#define MMM (10000)
void funcC() {
int N;
int M;
std::vector<int> A[NNN + 1];
int P[NNN];
int Y[NNN];
cin >> N;
cin >> M;
for (int m = 0; m < M; ++m) {
int p;
int y;
cin >> p;
cin >> y;
P[m] = p;
Y[m] = y;
}
for (int m = 0; m < M; ++m) {
A[P[m]].push_back(Y[m]);
}
for (int n = 1; n < N + 1; ++n) {
std::sort(A[n].begin(), A[n].end());
}
for (int m = 0; m < M; ++m) {
int p = P[m];
int y = Y[m];
int idx = std::lower_bound(A[p].begin(), A[p].end(), y) - A[p].begin();
printf("%.6d%.6d\n", p, idx + 1);
/*
int idx = -1;
for (int i = 0; i < A[p].size(); ++i) {
if (A[p][i] == y) {
//cerr << p << "," << i + 1 << endl;
printf("%.6d%.6d\n", p, i + 1);
}
}
*/
}
}
int main() {
// funcB();
funcC();
}
|
#include <algorithm>
#include <iostream>
#include <random>
#include <string>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;
#define NNN (100000)
#define MMM (10000)
void funcC() {
int N;
int M;
std::vector<int> A[NNN + 1];
int P[NNN];
int Y[NNN];
cin >> N;
cin >> M;
for (int m = 0; m < M; ++m) {
int p;
int y;
cin >> p;
cin >> y;
P[m] = p;
Y[m] = y;
}
for (int m = 0; m < M; ++m) {
A[P[m]].push_back(Y[m]);
}
for (int n = 1; n < N + 1; ++n) {
std::sort(A[n].begin(), A[n].end());
}
for (int m = 0; m < M; ++m) {
int p = P[m];
int y = Y[m];
int idx = std::lower_bound(A[p].begin(), A[p].end(), y) - A[p].begin();
printf("%.6d%.6d\n", p, idx + 1);
/*
int idx = -1;
for (int i = 0; i < A[p].size(); ++i) {
if (A[p][i] == y) {
//cerr << p << "," << i + 1 << endl;
printf("%.6d%.6d\n", p, i + 1);
}
}
*/
}
}
int main() {
// funcB();
funcC();
}
| replace | 12 | 13 | 12 | 13 | 0 | |
p03221 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#pragma comment(linker, "/stck:1024000000,1024000000")
#define lowbit(x) (x & (-x))
#define max(x, y) (x >= y ? x : y)
#define min(x, y) (x <= y ? x : y)
// #define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.1415926535897932384626433832
#define ios() ios::sync_with_stdio(true)
#define INF (1 << 31) - 1;
#define mem(a) (memset(a, 0, sizeof(a)))
#define ALL(a) (a).begin(), (a).end()
struct P {
int x, y;
} H[200000];
vector<int> G[100005];
int main() {
set<int> s;
int N, M;
int x, y;
cin >> N >> M;
for (int i = 1; i <= M; i++) {
cin >> x >> y;
H[i].x = x;
H[i].y = y;
G[x].push_back(y);
// s.insert(x);
}
for (int i = 1; i <= M; i++) {
sort(G[H[i].x].begin(), G[H[i].x].end());
}
for (int i = 1; i <= M; i++) {
cout << setw(6) << setfill('0') << H[i].x;
cout << setw(6) << setfill('0')
<< lower_bound(ALL(G[H[i].x]), H[i].y) - G[H[i].x].begin() + 1 << endl;
}
return 0;
}
| #include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#pragma comment(linker, "/stck:1024000000,1024000000")
#define lowbit(x) (x & (-x))
#define max(x, y) (x >= y ? x : y)
#define min(x, y) (x <= y ? x : y)
// #define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.1415926535897932384626433832
#define ios() ios::sync_with_stdio(true)
#define INF (1 << 31) - 1;
#define mem(a) (memset(a, 0, sizeof(a)))
#define ALL(a) (a).begin(), (a).end()
struct P {
int x, y;
} H[200000];
vector<int> G[100005];
int main() {
set<int> s;
int N, M;
int x, y;
cin >> N >> M;
for (int i = 1; i <= M; i++) {
cin >> x >> y;
H[i].x = x;
H[i].y = y;
G[x].push_back(y);
// s.insert(x);
}
for (int i = 1; i <= N; i++) {
sort(G[i].begin(), G[i].end());
}
for (int i = 1; i <= M; i++) {
cout << setw(6) << setfill('0') << H[i].x;
cout << setw(6) << setfill('0')
<< lower_bound(ALL(G[H[i].x]), H[i].y) - G[H[i].x].begin() + 1 << endl;
}
return 0;
}
| replace | 44 | 46 | 44 | 46 | TLE | |
p03221 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<vector<int>> yd(n + 1);
vector<int> p(n);
vector<int> y(n);
for (int i = 0; i < m; i++) {
cin >> p[i] >> y[i];
yd[p[i]].push_back(y[i]);
}
for (int i = 0; i < n; i++) {
sort(yd[i + 1].begin(), yd[i + 1].end());
}
for (int i = 0; i < m; i++) {
int num =
lower_bound(yd[p[i]].begin(), yd[p[i]].end(), y[i]) - yd[p[i]].begin();
printf("%06d%06d\n", p[i], num + 1);
}
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<vector<int>> yd(n + 1);
vector<int> p(m);
vector<int> y(m);
for (int i = 0; i < m; i++) {
cin >> p[i] >> y[i];
yd[p[i]].push_back(y[i]);
}
for (int i = 0; i < n; i++) {
sort(yd[i + 1].begin(), yd[i + 1].end());
}
for (int i = 0; i < m; i++) {
int num =
lower_bound(yd[p[i]].begin(), yd[p[i]].end(), y[i]) - yd[p[i]].begin();
printf("%06d%06d\n", p[i], num + 1);
}
}
| replace | 6 | 8 | 6 | 8 | 0 | |
p03221 | C++ | Time Limit Exceeded | #pragma GCC optimize( \
"O3,Ofast,inline,fast-math,unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define int int64_t
#define double long double
#define INIT \
std::ios_base::sync_with_stdio(0); \
std::cin.tie(0); \
std::cout << std::fixed << std::setprecision(15);
#define WRITE_FUNCTION_UNDER_HERE DEFALLTYPE(VDEF) DEFALLTYPE(PDEF3)
const int MOD = 1e9 + 7;
using namespace std;
const int MAX = std::numeric_limits<int>::max();
const int MIN = std::numeric_limits<int>::min();
const double EPS = 1e-7;
#define fou(i, a, n) for (int i = a; i < n; i++)
#define fod(i, a, n) for (int i = n - 1; i >= a; i--)
#define tra(e, v) for (auto &e : v)
#define elif(c) else if (c)
#define fi first
#define se second
#define fir fi
#define sec se.fi
#define thi se.se
#define firs fi
#define seco sec
#define thir thi.fi
#define four thi.se
#define DEFALLTYPE(XDEF) \
XDEF(int, I) \
XDEF(double, D) XDEF(char, C) XDEF(String, S) XDEF(bool, B) XDEF(Modulo, M)
#define VDEF(t, T) \
typedef Vector<t> V##T; \
typedef Vector<V##T> VV##T; \
typedef Vector<VV##T> VVV##T;
#define PDEF(x, X, y, Y, z, Z, w, W) \
typedef std::pair<x, y> P##X##Y; \
VDEF(P##X##Y, P##X##Y) typedef std::pair<x, std::pair<y, z>> P##X##Y##Z; \
VDEF(P##X##Y##Z, P##X##Y##Z) \
typedef std::pair<x, std::pair<y, std::pair<z, w>>> P##X##Y##Z##W; \
VDEF(P##X##Y##Z##W, P##X##Y##Z##W)
#define PDEF1(y, Y, z, Z, w, W) \
PDEF(int, I, y, Y, z, Z, w, W) \
PDEF(double, D, y, Y, z, Z, w, W) PDEF(char, C, y, Y, z, Z, w, W) \
PDEF(String, S, y, Y, z, Z, w, W) PDEF(bool, B, y, Y, z, Z, w, W) \
PDEF(Modulo, M, y, Y, z, Z, w, W)
#define PDEF2(z, Z, w, W) \
PDEF1(int, I, z, Z, w, W) \
PDEF1(double, D, z, Z, w, W) PDEF1(char, C, z, Z, w, W) \
PDEF1(String, S, z, Z, w, W) PDEF1(bool, B, z, Z, w, W) \
PDEF1(Modulo, M, z, Z, w, W)
#define PDEF3(w, W) \
PDEF2(int, I, w, W) \
PDEF2(double, D, w, W) PDEF2(char, C, w, W) PDEF2(String, S, w, W) \
PDEF2(bool, B, w, W) PDEF2(Modulo, M, w, W)
// in, out
#define in(T, ...) \
T __VA_ARGS__; \
_in(__VA_ARGS__)
void _in() {}
template <typename Hd, typename... Tl> void _in(Hd &hd, Tl &&...tl) {
std::cin >> hd;
_in(std::forward<Tl>(tl)...);
}
void out() { std::cout << '\n'; }
template <typename T> void out(const T &a) { std::cout << a << '\n'; }
template <typename Hd, typename... Tl> void out(const Hd &hd, const Tl &...tl) {
std::cout << hd << ' ';
out(tl...);
}
// std::pair io,calc
#define PairCalc(OP) \
template <typename T, typename U, typename V, typename W> \
std::pair<T, U> operator OP(const std::pair<T, U> &l, \
const std::pair<V, W> &r) { \
return std::make_pair(l.first OP r.first, l.second OP r.second); \
} \
template <typename T, typename U, typename V, typename W> \
std::pair<T, U> operator OP##=(std::pair<T, U> &l, \
const std::pair<V, W> &r) { \
return l = l OP r; \
}
template <typename T, typename U>
std::istream &operator>>(std::istream &i, std::pair<T, U> &p) {
i >> p.first >> p.second;
return i;
}
template <typename T, typename U>
std::ostream &operator<<(std::ostream &o, const std::pair<T, U> &p) {
return o << p.first << ' ' << p.second;
}
PairCalc(+) PairCalc(-) PairCalc(*) PairCalc(/) PairCalc(%) PairCalc(<<)
PairCalc(>>) PairCalc(&) PairCalc(|)
PairCalc(^) template <typename T, typename U>
std::pair<T, U> mp(const T &t, const U &u) {
return std::make_pair(t, u);
}
template <typename T, typename U, typename V>
std::pair<T, std::pair<U, V>> mp(const T &t, const U &u, const V &v) {
return std::make_pair(t, std::make_pair(u, v));
}
template <typename T, typename U, typename V, typename W>
std::pair<T, std::pair<U, std::pair<V, W>>> mp(const T &t, const U &u,
const V &v, const W &w) {
return std::make_pair(t, std::make_pair(u, std::make_pair(v, w)));
}
// Slice class, Vector class
struct Slice {
int first = 0;
int last = -1;
int step = 1;
Slice(int f, int l = -1, int s = 1) : first(f), last(l), step(s) {}
Slice(std::initializer_list<int> l) {
if (l.size() != 3)
return;
first = *l.begin();
last = *(l.begin() + 1);
step = *(l.begin() + 2);
}
};
#define VecCalc(OP) \
Vector<T> operator OP(const Vector<T> &r) const { \
Vector<T> v(std::min(size(), r.size())); \
for (int i = 0; i < v.size(); i++) \
v[i] = value[i] OP r[i]; \
return v; \
} \
Vector<T> operator OP(const T &r) const { \
Vector<T> v(size()); \
for (int i = 0; i < size(); i++) \
v[i] = value[i] OP r; \
return v; \
} \
Vector<T> operator OP##=(const Vector<T> &r) { return *this = *this OP r; } \
Vector<T> operator OP##=(const T &r) { return *this = *this OP r; }
#define VecComp(OP) \
Vector<int> operator OP(const Vector<T> &r) const { \
Vector<int> v(std::min(size(), r.size())); \
for (int i = 0; i < v.size(); i++) \
v[i] = value[i] OP r[i]; \
return v; \
} \
Vector<int> operator OP(const T &r) const { \
Vector<int> v(size()); \
for (int i = 0; i < size(); i++) \
v[i] = value[i] OP r; \
return v; \
}
#define VVCalc(OP) \
template <typename T, typename U> \
Vector<Vector<T>> operator OP(Vector<Vector<T>> l, const U &r) { \
for (Vector<T> & e : l) \
e OP## = r; \
return l; \
} \
template <typename T, typename U> \
Vector<Vector<T>> operator OP##=(Vector<Vector<T>> &l, const U &r) { \
return l = l OP r; \
}
#define VVComp(OP) \
template <typename T, typename U> \
Vector<Vector<int>> operator OP(const Vector<Vector<T>> &l, const U &r) { \
Vector<Vector<int>> v(l.size()); \
for (int i = 0; i < l.size(); i++) \
v[i] = l[i] OP r; \
return v; \
}
template <typename T> class Vector {
std::vector<T> value;
public:
Vector(int s = 0, T v = T()) {
if (s >= 0)
assign(s, v);
else {
assign(-s, v);
for (T &e : value)
std::cin >> e;
}
}
Vector(const std::initializer_list<T> &l) { value = std::vector<T>{l}; }
template <typename U> Vector(const Vector<U> &v) {
resize(v.size());
for (int i = 0; i < size(); i++)
value[i] = v[i];
}
Vector(const std::vector<T> &v) { value = v; }
int size() const { return value.size(); }
T operator[](int i) const { return value[i]; }
T &operator[](int i) { return value[i]; }
Vector<T> operator[](Slice s) const {
s.last = (s.last < 0 ? s.last + size() + 1 : s.last);
Vector<T> v;
for (int i = s.first; i < s.last; i += s.step)
v.pub(value[i]);
return v;
}
Vector<T> &operator=(const Vector<T> &v) {
resize(v.size());
for (int i = 0; i < size(); i++)
value[i] = v[i];
return *this;
}
Vector<T> operator+() const { return *this; }
Vector<T> operator-() const {
Vector<T> v(value.size());
for (int i = 0; i < size(); i++)
v[i] = -value[i];
return v;
}
Vector<T> operator++() {
for (T &e : value)
e++;
return *this;
}
Vector<T> operator--() {
for (T &e : value)
e--;
return *this;
}
Vector<T> operator++(int32_t) {
Vector<T> v = *this;
for (T &e : value)
e++;
return v;
}
Vector<T> operator--(int32_t) {
Vector<T> v = *this;
for (T &e : value)
e--;
return v;
}
std::vector<T> stdVector() const { return value; }
std::vector<T> &stdVector() { return value; }
void out() {
for (const T &e : value)
std::cout << e << '\n';
}
void iota() {
for (int i = 0; i < size(); i++)
value[i] = i;
}
Vector<T> iotaed() const {
Vector<T> r(*this);
r.iota();
return r;
}
T last() const { return value[size() - 1]; }
T &last() { return value[size() - 1]; }
auto begin() { return value.begin(); }
auto end() { return value.end(); }
auto begin() const { return value.begin(); }
auto end() const { return value.end(); }
T sum(int l = 0, int r = -1) const {
T v = T();
r = (r < 0 ? r + size() + 1 : r);
for (int i = l; i < r; i++)
v += value[i];
return v;
}
T prod(int l = 0, int r = -1) const {
T v = T() + 1;
r = (r < 0 ? r + size() + 1 : r);
for (int i = l; i < r; i++)
v *= value[i];
return v;
}
T xorsum(int l = 0, int r = -1) const {
T v = T();
r = (r < 0 ? r + size() + 1 : r);
for (int i = l; i < r; i++)
v ^= value[i];
return v;
}
int argmin() const { return std::min_element(begin(), end()) - begin(); }
int argmax() const { return std::max_element(begin(), end()) - begin(); }
T min() const { return value[argmin()]; }
T max() const { return value[argmax()]; }
T dot(const Vector<T> &v) const {
T r = T();
for (int i = 0; i < std::min(size(), v.size()); i++)
r += value[i] * v[i];
return r;
}
void resize(int s, T v = T()) { value.resize(s, v); }
void assign(int s, const T &v) { value.assign(s, v); }
void pub(const T &v) { value.push_back(v); }
void pub(const Vector<T> &v) { value.insert(end(), v.begin(), v.end()); }
void insert(int i, const T &v) { value.insert(begin() + i, v); }
void insert(int i, const Vector<T> &v) {
value.insert(begin() + i, v.begin(), v.end());
}
void pob() { value.pop_back(); }
void erase(int i, int j = -1) {
if (j < 0)
value.erase(begin() + i);
else
value.erase(begin() + i, begin() + j);
}
void erase_unique() { value.erase(std::unique(begin(), end()), end()); }
void reverse() { std::reverse(begin(), end()); }
void rotatedown(int i) {
if (i > 0)
std::rotate(begin(), begin() + i, end());
}
void rotateup(int i) {
if (i > 0)
std::rotate(value.rbegin(), value.rbegin() + i, value.rend());
}
void sortup() { std::sort(begin(), end()); }
void sortdown() { std::sort(value.rbegin(), value.rend()); }
void cumsum() {
for (int i = 0; i < size() - 1; i++)
value[i + 1] += value[i];
}
void sumdiff() {
for (int i = size() - 2; i >= 0; i--)
value[i + 1] -= value[i];
}
T cumsumpart(int l, int r) const {
return value[r - 1] - (l = 0 ? 0 : value[l - 1]);
}
void cumxorsum() {
for (int i = 0; i < size() - 1; i++)
value[i + 1] ^= value[i];
}
void xorsumdiff() {
for (int i = size() - 2; i >= 0; i--)
value[i + 1] ^= value[i];
}
T cumxorsumpart(int l, int r) const {
return value[r - 1] ^ (l = 0 ? 0 : value[l - 1]);
}
void bucketsortup() {
int m = min();
Vector<int> b(max() - m + 1);
for (int e : value)
b[e - m]++;
b.cumsum();
for (int i = 0; i < b.size(); i++)
for (int j = (i == 0 ? 0 : b[i - 1]); j < b[i]; j++)
value[j] = m + i;
}
void bucketsortdown() {
bucketsortup();
reverse();
}
void compress() {
Vector<T> u(value);
u.sortup();
u.erase_unique();
std::unordered_map<T, int> m;
for (int i = 0; i < u.size(); i++)
m[u[i]] = i;
for (int i = 0; i < size(); i++)
value[i] = m[value[i]];
}
void argofsortup() {
Vector<std::pair<T, T>> p(size());
for (int i = 0; i < size(); i++)
p[i] = std::make_pair(value[i], i);
p.sortup();
for (int i = 0; i < size(); i++)
value[i] = p[i].second;
}
void argofsortdown() {
Vector<std::pair<T, T>> p(size());
for (int i = 0; i < size(); i++)
p[i] = std::make_pair(value[i], i);
p.sortdown();
for (int i = 0; i < size(); i++)
value[i] = p[i].second;
}
int findupgeq(const T &v) {
return std::lower_bound(begin(), end(), v) - begin();
}
int findupleq(const T &v) {
return std::upper_bound(begin(), end(), v) - begin() - 1;
}
int upcount(const T &v) { return findupleq(v) - findupgeq(v) + 1; }
int finddowngeq(const T &v) {
return size() -
(std::lower_bound(value.rbegin(), value.rend(), v) -
value.rbegin()) -
1;
}
int finddownleq(const T &v) {
return size() -
(std::upper_bound(value.rbegin(), value.rend(), v) - value.rbegin());
}
int downcount(const T &v) { return finddowngeq(v) - finddownleq(v) + 1; }
VecCalc(+) VecCalc(-) VecCalc(*) VecCalc(/) VecCalc(%) VecCalc(<<) VecCalc(>>)
VecCalc(&) VecCalc(|) VecCalc(^) VecComp(==) VecComp(!=) VecComp(>=)
VecComp(<=) VecComp(>) VecComp(<) Vector<T> pubed(const T &v) const {
Vector<T> r(*this);
r.pub(v);
return r;
}
Vector<T> pubed(const Vector<T> &v) const {
Vector<T> r(*this);
r.pub(v);
return r;
}
Vector<T> inserted(int i, const T &v) const {
Vector<T> r(*this);
r.insert(i, v);
return r;
}
Vector<T> inserted(int i, const Vector<T> &v) const {
Vector<T> r(*this);
r.insert(i, v);
return r;
}
Vector<T> pobed() const {
Vector<T> r(*this);
r.pob();
return r;
}
Vector<T> erased(int i, int j = -1) const {
Vector<T> r(*this);
r.erase(i, j);
return r;
}
Vector<T> erase_uniqued() const {
Vector<T> r(*this);
r.erase_unique();
return r;
}
Vector<T> reversed() const {
Vector<T> r(*this);
r.reverse();
return r;
}
Vector<T> rotatedowned(int i) const {
Vector<T> r(*this);
r.rotatedown(i);
return r;
}
Vector<T> rotateuped(int i) const {
Vector<T> r(*this);
r.rotateup(i);
return r;
}
Vector<T> sortuped() const {
Vector<T> r(*this);
r.sortup();
return r;
}
Vector<T> sortdowned() const {
Vector<T> r(*this);
r.sortdown();
return r;
}
Vector<T> cumsumed() const {
Vector<T> r(*this);
r.cumsum();
return r;
}
Vector<T> sumdiffed() const {
Vector<T> r(*this);
r.sumdiff();
return r;
}
Vector<T> cumxorsumed() const {
Vector<T> r(*this);
r.cumxorsum();
return r;
}
Vector<T> xorsumdiffed() const {
Vector<T> r(*this);
r.xorsumdiff();
return r;
}
Vector<T> bucketsortuped() const {
Vector<T> r(*this);
r.bucketsortup();
return r;
}
Vector<T> bucketsortdowned() const {
Vector<T> r(*this);
r.bucketsortdown();
return r;
}
Vector<T> compressed() const {
Vector<T> r(*this);
r.compress();
return r;
}
Vector<T> argofsortuped() const {
Vector<T> r(*this);
r.argofsortup();
return r;
}
Vector<T> argofsortdowned() const {
Vector<T> r(*this);
r.argofsortdown();
return r;
}
};
VVCalc(+) VVCalc(-) VVCalc(*) VVCalc(/) VVCalc(%) VVCalc(<<) VVCalc(>>)
VVCalc(&) VVCalc(|) VVCalc(^) VVComp(==) VVComp(!=) VVComp(>=) VVComp(<=)
VVComp(>) VVComp(<) template <typename T, typename U>
Vector<std::pair<T, U>> unite(const Vector<T> &v, const Vector<U> &u) {
int s = std::min(v.size(), u.size());
Vector<std::pair<T, U>> r(s);
for (int i = 0; i < s; i++)
r[i] = std::make_pair(v[i], u[i]);
return r;
}
template <typename T, typename U>
std::pair<Vector<T>, Vector<U>> separate(const Vector<std::pair<T, U>> &p) {
Vector<T> v(p.size());
Vector<U> u(p.size());
for (int i = 0; i < p.size(); i++) {
v[i] = p[i].first;
u[i] = p[i].second;
}
return std::make_pair(v, u);
}
template <typename T> std::istream &operator>>(std::istream &i, Vector<T> &v) {
for (T &e : v)
i >> e;
return i;
}
template <typename T>
std::ostream &operator<<(std::ostream &o, const Vector<T> &v) {
if (v.size() == 0)
return o;
for (int i = 0; i < v.size() - 1; i++)
o << v[i] << ' ';
return o << v.last();
}
Vector<int> baseVector(int n, int b) {
Vector<int> v(64);
for (int &e : v) {
e = n % b;
n /= b;
}
return v;
}
int baseVectorValue(Vector<int> v, int b) {
int n = 0, m = 1;
for (int &e : v) {
n += e * m;
m *= b;
}
return n;
}
// Matrix class need Vector class
#define MatCalc(OP) \
Matrix<T> operator OP(const Matrix<T> &r) const { \
Matrix<T> v(std::min(size(), r.size())); \
for (int i = 0; i < v.size(); i++) \
v[i] = value[i] OP r[i]; \
return v; \
} \
Matrix<T> operator OP(const Vector<T> &r) const { \
Matrix<T> v(std::min(size(), r.size())); \
for (int i = 0; i < size(); i++) \
v[i] = value[i] OP r; \
return v; \
} \
Matrix<T> operator OP(const T &r) const { \
Matrix<T> v(size()); \
for (int i = 0; i < size(); i++) \
v[i] = value[i] OP r; \
return v; \
} \
Matrix<T> operator OP##=(const Matrix<T> &r) { return *this = *this OP r; } \
Matrix<T> operator OP##=(const Vector<T> &r) { return *this = *this OP r; } \
Matrix<T> operator OP##=(const T &r) { return *this = *this OP r; }
#define MatComp(OP) \
Matrix<int> operator OP(const Matrix<T> &r) const { \
Matrix<int> v(std::min(size(), r.size())); \
for (int i = 0; i < v.size(); i++) \
v[i] = value[i] OP r[i]; \
return v; \
} \
Matrix<int> operator OP(const Vector<T> &r) const { \
Matrix<int> v(size()); \
for (int i = 0; i < size(); i++) \
v[i] = value[i] OP r; \
return v; \
} \
Matrix<int> operator OP(const T &r) const { \
Matrix<int> v(size()); \
for (int i = 0; i < size(); i++) \
v[i] = value[i] OP r; \
return v; \
}
template <typename T> class Matrix {
Vector<Vector<T>> value;
public:
Matrix(int c = 0, int r = 0, T v = T()) {
if (c >= 0 && r >= 0)
assign(c, r, v);
else {
assign(-c, -r, v);
for (Vector<T> &e : value)
std::cin >> e;
}
}
Matrix(std::pair<int, int> p, T v = T()) {
if (p.first >= 0 && p.second >= 0)
assign(p.first, p.second, v);
else {
resize(-p.first, -p.second);
for (Vector<T> &e : value)
std::cin >> e;
}
}
Matrix(const std::initializer_list<std::initializer_list<T>> &l) {
value.resize(l.size());
for (int i = 0; i < size(); i++)
value[i] = *(l.begin() + i);
rect();
}
template <typename U> Matrix(const Matrix<U> &v) {
resize(v.size());
for (int i = 0; i < size(); i++)
value[i] = v[i];
}
Matrix(const Vector<Vector<T>> &v) {
value.resize(v.size());
for (int i = 0; i < size(); i++)
value[i] = v[i];
rect();
}
Matrix(const std::vector<std::vector<T>> &v) {
value.resize(v.size());
for (int i = 0; i < size(); i++)
value[i] = v[i];
rect();
}
void rect() {
Vector<T> v(size());
for (int i = 0; i < size(); i++)
v[i] = value[i].size();
resize(size(), v.max());
}
int size() const { return value.size(); }
std::pair<int, int> shape() const {
return std::make_pair(size(), size() == 0 ? 0 : value[0].size());
}
Vector<T> operator[](int i) const { return value[i]; }
Vector<T> &operator[](int i) { return value[i]; }
T operator[](std::pair<int, int> p) const { return value[p.first][p.second]; }
T &operator[](std::pair<int, int> p) { return value[p.first][p.second]; }
Matrix<T> operator[](Slice p) const { return value[p]; }
Matrix<T> operator[](std::pair<Slice, Slice> p) const {
p.first.last =
(p.first.last < 0 ? p.first.last + shape().first + 1 : p.first.last);
p.second.last = (p.second.last < 0 ? p.second.last + shape().second + 1
: p.second.last);
Matrix<T> v;
for (int i = p.first.first; i < p.first.last; i += p.first.step) {
Vector<T> u;
for (int j = p.second.first; j < p.second.last; j += p.second.step)
u.pub(value[i][j]);
v.vstack(u);
}
return v;
}
Matrix<T> &operator=(const Matrix<T> &v) {
value.resize(size());
for (int i = 0; i < v.size(); i++)
value[i] = v[i];
return *this;
}
Matrix<T> operator+() const { return *this; }
Matrix<T> operator-() const {
Matrix<T> v(value.size());
for (int i = 0; i < size(); i++)
v[i] = -value[i];
return v;
}
Matrix<T> operator++() {
for (Vector<T> &e : value)
e++;
return *this;
}
Matrix<T> operator--() {
for (Vector<T> &e : value)
e--;
return *this;
}
Matrix<T> operator++(int32_t) {
Matrix<T> v = *this;
for (Vector<T> &e : value)
e++;
return v;
}
Matrix<T> operator--(int32_t) {
Matrix<T> v = *this;
for (Vector<T> &e : value)
e--;
return v;
}
std::vector<std::vector<T>> stdVector() {
std::vector<std::vector<T>> v(size());
for (int i = 0; i < size(); i++)
v[i] = value[i].stdVector();
return v;
}
void out() {
for (const Vector<T> &e : value)
std::cout << e << '\n';
}
Vector<Vector<T>> vectorVector() { return value; }
Vector<T> last() const { return value[size() - 1]; }
Vector<T> &last() { return value[size() - 1]; }
Vector<T> vector() const {
Vector<T> v;
for (const Vector<T> &e : value)
v.pub(e);
return v;
}
auto begin() { return value.begin(); }
auto end() { return value.end(); }
auto begin() const { return value.begin(); }
auto end() const { return value.end(); }
T sum(int cl = 0, int rl = 0, int cr = -1, int rr = -1) const {
T v = T();
cr = (cr < 0 ? cr + size() + 1 : cr);
for (int i = cl; i < cr; i++)
v += value[i].sum(rl, rr);
return v;
}
T prod(int cl = 0, int rl = 0, int cr = -1, int rr = -1) const {
T v = T() + 1;
cr = (cr < 0 ? cr + size() + 1 : cr);
for (int i = cl; i < cr; i++)
v *= value[i].prod(rl, rr);
return v;
}
T xorsum(int cl = 0, int rl = 0, int cr = -1, int rr = -1) const {
T v = T();
cr = (cr < 0 ? cr + size() + 1 : cr);
for (int i = cl; i < cr; i++)
v ^= value[i].xorsum(rl, rr);
return v;
}
std::pair<int, int> argmin() const {
Vector<int> v(size());
for (int i = 0; i < size(); i++)
v[i] = value[i].min();
int m = v.argmin();
return std::make_pair(m, value[m].argmin());
}
std::pair<int, int> argmax() const {
Vector<int> v(size());
for (int i = 0; i < size(); i++)
v[i] = value[i].max();
int m = v.argmax();
return std::make_pair(m, value[m].argmax());
}
T min() const {
Vector<int> v(size());
for (int i = 0; i < size(); i++)
v[i] = value[i].min();
return v.min();
}
T max() const {
Vector<int> v(size());
for (int i = 0; i < size(); i++)
v[i] = value[i].max();
return v.max();
}
void dot(Matrix<T> v) {
Matrix<T> m(value);
assign(shape().first, v.shape().second, 0);
for (int i = 0; i < shape().first; i++)
for (int j = 0; j < shape().second; j++)
for (int k = 0; k < std::min(m.shape().second, v.shape().first); k++)
value[i][j] += m[i][k] * v[k][j];
}
void resize(int c, Vector<T> v = Vector<T>()) { value.resize(c, v); }
void resize(int c, int r, T v = T()) {
resize(c);
for (Vector<T> &e : value)
e.resize(r, v);
}
void resize(std::pair<int, int> p, T v = T()) {
resize(p.first, p.second, v);
}
void assign(int c, const Vector<T> &v) { value.assign(c, v); }
void assign(int c, int r, T v) { assign(c, Vector<T>(r, v)); }
void assign(std::pair<int, int> p, const T &v) {
assign(p.first, p.second, v);
}
void vstack(const Vector<T> &v) {
if (shape().second < v.size() && size() > 0) {
value.pub(v[{0, shape().second, 1}]);
} else {
value.pub(v);
value.last().resize(shape().second);
}
}
void vstack(const Matrix<T> &v) {
Matrix<T> u(
v[{{0, -1, 1}, {0, std::min(shape().second, v.shape().second), 1}}]);
for (const Vector<T> &e : u)
vstack(e);
}
void hstack(const Vector<T> &v) {
if (size() == 0)
resize(v.size());
for (int i = 0; i < std::min(size(), v.size()); i++)
value[i].pub(v[i]);
resize(shape());
}
void hstack(const Matrix<T> &v) {
if (size() == 0)
resize(v.size());
for (int i = 0; i < std::min(size(), v.size()); i++)
value[i].pub(v[i]);
resize(shape());
}
void vpob() { value.pob(); }
void hpob() {
for (Vector<T> &e : value)
e.pob();
}
void verase(int i, int j = -1) {
if (j == -1)
value.erase(i);
else
value.erase(i, j);
}
void herase(int i, int j = -1) {
for (Vector<T> &e : value)
if (j == -1)
e.erase(i);
else
e.erase(i, j);
}
void vinsert(int i, const Vector<T> &v) {
if (shape() == std::make_pair(int(0), int(0)))
vstack(v);
else
value.insert(i, v[{0, shape().second, 1}]);
}
void vinsert(int i, const Matrix<T> &v) {
if (shape() == std::make_pair(int(0), int(0)))
vstack(v);
else
value.insert(
i, v[{{0, -1, 1}, {0, std::min(shape().second, v.shape().second), 1}}]
.vectorVector());
}
void hinsert(int i, const Vector<T> &v) {
if (shape() == std::make_pair(int(0), int(0)))
hstack(v);
else
for (int j = 0; j < std::min(size(), v.size()); j++)
value[j].insert(i, v[j]);
for (int j = std::min(size(), v.size()); j < size(); j++)
value[j].insert(i, 0);
}
void hinsert(int i, const Matrix<T> &v) {
if (shape() == std::make_pair(int(0), int(0)))
hstack(v);
else
for (int j = 0; j < std::min(size(), v.size()); j++)
value[j].insert(i, v[j]);
for (int j = std::min(size(), v.size()); j < size(); j++)
value[j].resize(v.shape().second);
}
void transpose() {
std::pair<int, int> s = shape();
if (s.first < s.second)
for (int i = 0; i < s.second - s.first; i++)
value.pub(Vector<T>(s.first));
else
for (int i = 0; i < s.second; i++)
value[i].resize(s.first);
for (int i = 0; i < std::min(s.first, s.second); i++)
for (int j = i + 1; j < size(); j++)
std::swap(value[i][j], value[j][i]);
resize(s.second, s.first);
}
void power(int n) {
Matrix<T> m(*this);
assign(size(), size(), 0);
for (int i = 0; i < size(); i++)
value[i][i] = 1;
while (n > 0) {
if (n & 1)
dot(m);
m.dot(m);
n /= 2;
}
}
void cumsum() {
value.cumsum();
for (Vector<T> &e : value)
e.cumsum();
}
void sumdiff() {
value.sumdiff();
for (Vector<T> &e : value)
e.sumdiff();
}
T cumsumpart(int cl, int rl, int cr, int rr) const {
return value[cr - 1][rr - 1] - (cl == 0 ? 0 : value[cl - 1][rr - 1]) -
(rl == 0 ? 0 : value[cr - 1][rl - 1]) +
((cl == 0 || rl == 0) ? 0 : value[cl - 1][rl - 1]);
}
void cumxorsum() {
value.cumxorsum();
for (Vector<T> &e : value)
e.cumxorsum();
}
void xorsumdiff() {
value.xorsumdiff();
for (Vector<T> &e : value)
e.xorsumdiff();
}
T cumxorsumpart(int cl, int rl, int cr, int rr) const {
return value[cr - 1][rr - 1] ^ (cl == 0 ? 0 : value[cl - 1][rr - 1]) ^
(rl == 0 ? 0 : value[cr - 1][rl - 1]) ^
((cl == 0 || rl == 0) ? 0 : value[cl - 1][rl - 1]);
}
void compress() {
Vector<T> u = vector();
u.sortup();
u.erase_unique();
std::unordered_map<T, int> m;
for (int i = 0; i < u.size(); i++)
m[u[i]] = i;
for (int i = 0; i < shape().first; i++)
for (int j = 0; j < shape().second; j++)
value[i][j] = m[value[i][j]];
}
MatCalc(+) MatCalc(-) MatCalc(*) MatCalc(/) MatCalc(%) MatCalc(<<) MatCalc(>>)
MatCalc(&) MatCalc(|) MatCalc(^) MatComp(==) MatComp(!=) MatComp(>=)
MatComp(<=) MatComp(>)
MatComp(<) Matrix<T> vstacked(const Vector<T> &v) const {
Matrix<T> r(*this);
r.vstack(v);
return r;
}
Matrix<T> vstacked(const Matrix<T> &v) const {
Matrix<T> r(*this);
r.vstack(v);
return r;
}
Matrix<T> hstacked(const Vector<T> &v) const {
Matrix<T> r(*this);
r.hstack(v);
return r;
}
Matrix<T> hstacked(const Matrix<T> &v) const {
Matrix<T> r(*this);
r.hstack(v);
return r;
}
Matrix<T> vpobed() const {
Matrix<T> r(*this);
r.vpob();
return r;
}
Matrix<T> hpobed() const {
Matrix<T> r(*this);
r.hpob();
return r;
}
Matrix<T> verased(int i, int j = -1) const {
Matrix<T> r(*this);
r.verase(i, j);
return r;
}
Matrix<T> herased(int i, int j = -1) const {
Matrix<T> r(*this);
r.herase(i, j);
return r;
}
Matrix<T> vinserted(int i, const Vector<T> &v) const {
Matrix<T> r(*this);
r.vinsert(i, v);
return r;
}
Matrix<T> vinserted(int i, const Matrix<T> &v) const {
Matrix<T> r(*this);
r.vinsert(i, v);
return r;
}
Matrix<T> hinserted(int i, const Vector<T> &v) const {
Matrix<T> r(*this);
r.hinsert(i, v);
return r;
}
Matrix<T> hinserted(int i, const Matrix<T> &v) const {
Matrix<T> r(*this);
r.hinsert(i, v);
return r;
}
Matrix<T> transposed() const {
Matrix<T> r(*this);
r.transpose();
return r;
}
Matrix<T> powered(int n) const {
Matrix<T> r(*this);
r.power(n);
return r;
}
Matrix<T> cumsumed() const {
Matrix<T> r(*this);
r.cumsum();
return r;
}
Matrix<T> sumdiffed() const {
Matrix<T> r(*this);
r.sumdiff();
return r;
}
Matrix<T> cumxorsumed() const {
Matrix<T> r(*this);
r.cumxorsum();
return r;
}
Matrix<T> xorsumdiffed() const {
Matrix<T> r(*this);
r.xorsumdiff();
return r;
}
Matrix<T> compressed() const {
Matrix<T> r(*this);
r.compress();
return r;
}
};
// String class need Vector class
#define DefOtherType(RTYPE, OP, CONST) \
RTYPE operator OP(const char *s) CONST { return operator OP(String(s)); } \
RTYPE operator OP(const std::string &s) CONST { \
return operator OP(String(s)); \
} \
RTYPE operator OP(char c) CONST { return operator OP(String(c)); }
#define StrComp(OP) \
bool operator OP(const String &s) const { return str OP s.stdString(); } \
DefOtherType(bool, OP, const)
class String {
std::string str;
public:
String() {}
String(const char *s) : str(s) {}
String(char s) : str(1, s) {}
String(int i, char c) { str = std::string(i, c); }
String(int32_t i) : str(std::to_string(i)) {}
String(int64_t i) : str(std::to_string(i)) {}
String(const std::string &s) : str(s) {}
String(const Vector<char> &v) {
for (char c : v)
pub(c);
}
char operator[](int i) const { return str[i]; }
char &operator[](int i) { return str[i]; }
String operator[](Slice s) const {
s.last = (s.last < 0 ? s.last + size() + 1 : s.last);
String r;
for (int i = s.first; i < s.last; i += s.step)
r.pub(str[i]);
return r;
}
void operator--(int32_t) { pob(); }
String &operator=(const String &s) {
str = s.stdString();
return *this;
}
DefOtherType(String &, =, ) String &operator<<(const String &s) {
pub(s);
return *this;
}
DefOtherType(String &, <<, ) String operator+(const String &s) const {
String r(*this);
r.pub(s);
return r;
}
DefOtherType(String, +, const) String operator+=(const String &s) {
pub(s);
return *this;
}
DefOtherType(String, +=, ) StrComp(==) StrComp(!=) StrComp(>=) StrComp(<=)
StrComp(>) StrComp(<) std::string stdString() const {
return str;
}
std::string &stdString() { return str; }
char last() const { return str[size() - 1]; }
Vector<char> toVector() const {
Vector<char> v;
for (char c : str)
v.pub(c);
return v;
}
char &last() { return str[size() - 1]; }
auto begin() { return str.begin(); }
auto end() { return str.end(); }
auto begin() const { return str.begin(); }
auto end() const { return str.end(); }
int size() const { return str.size(); }
String substr(int p, int s = -1) const {
return operator[]({p, s < 0 ? s : p + s, 1});
}
int32_t toInt() { return std::stoi(str); }
int64_t toLong() { return std::stol(str); }
Vector<int> find(const String &s) const {
Vector<int> v;
auto i = str.find(s.stdString());
while (i != std::string::npos) {
v.pub(i);
i = str.find(s.stdString(), i + s.size());
}
return v;
}
Vector<int> find_dup(const String &s) const {
Vector<int> v;
auto i = str.find(s.stdString());
while (i != std::string::npos) {
v.pub(i);
i = str.find(s.stdString(), i + 1);
}
return v;
}
void resize(int i, char c = 0) { str.resize(i, c); }
void assign(int i, char c) { str.assign(i, c); }
void pub(const String &s) { str += s.stdString(); }
void pob() { str.pop_back(); }
void reverse() { std::reverse(begin(), end()); }
void insert(int i, const String &s) { str.insert(i, s.stdString()); }
void erase(int i, int j = -1) {
if (j < 0)
str.erase(i, 1);
else
str.erase(i, j - i);
}
void erase_unique() { str.erase(std::unique(begin(), end()), end()); }
void rotatedown(int i) { std::rotate(begin(), begin() + i, end()); }
void rotateup(int i) {
std::rotate(str.rbegin(), str.rbegin() + i, str.rend());
}
void sortup() {
int m = *std::min_element(begin(), end());
int M = *std::max_element(begin(), end());
Vector<char> b(M - m + 1);
for (char e : str)
b[e - m]++;
b.cumsum();
for (int i = 0; i < b.size(); i++)
for (int j = (i == 0 ? 0 : b[i - 1]); j < b[i]; j++)
str[j] = m + i;
}
void sortdown() {
sortup();
reverse();
}
String reversed() const {
String r(*this);
r.reverse();
return r;
}
String inserted(int i, const String &s) const {
String r(*this);
r.insert(i, s);
return r;
}
String erased(int i, int j = -1) const {
String r(*this);
r.erase(i, j);
return r;
}
String erase_uniqued() const {
String r(*this);
r.erase_unique();
return r;
}
String rotatedowned(int i) const {
String r(*this);
r.rotatedown(i);
return r;
}
String rotateuped(int i) const {
String r(*this);
r.rotateup(i);
return r;
}
String sortuped() const {
String r(*this);
r.sortup();
return r;
}
String sortdowned() const {
String r(*this);
r.sortdown();
return r;
}
};
std::istream &operator>>(std::istream &i, String &s) {
i >> s.stdString();
return i;
}
std::ostream &operator<<(std::ostream &o, const String &s) {
return o << s.stdString();
}
// Modulo class
#define ModCalc(OP) \
Modulo operator OP(const Modulo &l, const Modulo &r) { \
return Modulo(l.val() OP r.val()); \
} \
Modulo operator OP(const Modulo &l, const int64_t &r) { \
return Modulo(l.val() OP Modulo(r)); \
} \
Modulo operator OP(const int64_t &l, const Modulo &r) { \
return Modulo(l) OP r.val(); \
} \
Modulo operator OP##=(Modulo &l, const Modulo &r) { return l = l OP r; } \
Modulo operator OP##=(Modulo &l, const int64_t &r) { return l = l OP r; } \
int64_t operator OP##=(int64_t &l, const Modulo &r) { \
return l = l OP r.val(); \
}
#define ModComp(OP) \
bool operator OP(const Modulo &l, const Modulo &r) { \
return l.val() OP r.val(); \
} \
bool operator OP(const Modulo &l, const int64_t &r) { return l.val() OP r; } \
bool operator OP(const int64_t &l, const Modulo &r) { return l OP r.val(); }
class Modulo {
int64_t value;
public:
Modulo() : value(0) {}
Modulo(const int64_t &v) {
value = v;
normalize();
}
void normalize() { value = (value % mod() + mod()) % mod(); }
Modulo(const Modulo &m) : value(m.val()) {}
Modulo inv() const {
int64_t a = value;
int64_t b = mod(), u = 0, v = 1;
while (a > 1) {
u -= b / a * v;
b %= a;
std::swap(a, b);
std::swap(u, v);
}
return Modulo(v);
}
int64_t val() const { return value; }
int64_t &val() { return value; }
Modulo &operator=(const Modulo &m) {
value = m.val();
return *this;
}
int64_t mod() const { return MOD; }
Modulo &operator=(const int64_t &v) {
value = v;
return *this;
}
Modulo operator++() { return Modulo(++value); }
Modulo operator--() { return Modulo(--value); }
Modulo operator++(int32_t) { return Modulo(value++); }
Modulo operator--(int32_t) { return Modulo(value--); }
Modulo operator+() const { return *this; }
Modulo operator-() const { return Modulo(-value); }
Modulo power(int64_t i) const {
int64_t x = value;
int64_t r = 1;
while (i > 0) {
if (i & 1)
r = r * x % mod();
x = x * x % mod();
i /= 2;
}
return Modulo(r);
}
};
std::ostream &operator<<(std::ostream &o, const Modulo &m) {
return o << m.val();
}
std::istream &operator>>(std::istream &i, Modulo &m) {
i >> m.val();
m.normalize();
return i;
}
ModCalc(+) ModCalc(-) ModCalc(*) ModCalc(<<) ModCalc(>>) ModCalc(&) ModCalc(|)
ModCalc(^) ModComp(==) ModComp(!=) ModComp(>=) ModComp(<=) ModComp(>)
ModComp(<) Modulo
operator/(const Modulo &l, const Modulo &r) {
return Modulo(l.val() * r.inv());
}
Modulo operator/(const Modulo &l, const int64_t &r) {
return Modulo(l.val() * Modulo(r).inv());
}
Modulo operator/(const int64_t &l, const Modulo &r) {
return Modulo(Modulo(l) * r.inv());
}
// FFT, NNT need Vector Modulo class
std::unordered_map<int, int> MOD_ROOT = {
{1224736769, 3}, {1053818881, 7}, {1051721729, 6}, {1045430273, 3},
{1012924417, 5}, {1007681537, 3}, {1004535809, 3}, {998244353, 3},
{985661441, 3}, {976224257, 3}, {975175681, 17}, {962592769, 7},
{950009857, 7}, {943718401, 7}, {935329793, 3}, {924844033, 5},
{469762049, 3}, {167772161, 3}};
Vector<std::complex<double>> fft(Vector<std::complex<double>> a,
bool inverse = false) {
int n = a.size(), h = std::log2(n);
for (int i = 0; i < n; i++) {
int j = 0;
for (int k = 0; k < h; k++)
j |= (i >> k & 1) << (h - 1 - k);
if (i < j)
std::swap(a[i], a[j]);
}
for (int b = 1; b < n; b *= 2) {
for (int j = 0; j < b; j++) {
std::complex<double> w =
std::polar(1.0, (2 * M_PI) / (2 * b) * j * (inverse ? 1 : -1));
for (int k = 0; k < n; k += b * 2) {
std::complex<double> s = a[j + k], t = a[j + k + b] * w;
a[j + k] = s + t;
a[j + k + b] = s - t;
}
}
}
a /= std::complex<double>(inverse ? n : 1);
return a;
}
Vector<Modulo> ntt(Vector<Modulo> a, bool inverse = false) {
int n = a.size(), h = std::log2(n);
Modulo root = MOD_ROOT[MOD];
for (int i = 0; i < n; i++) {
int j = 0;
for (int k = 0; k < h; k++)
j |= (i >> k & 1) << (h - 1 - k);
if (i < j)
std::swap(a[i], a[j]);
}
for (int b = 1; b < n; b *= 2) {
Modulo w = root.power((a[0].mod() - 1) / (b * 2));
if (inverse)
w = w.inv();
for (int j = 0; j < n; j += b * 2) {
Modulo wn = 1;
for (int k = 0; k < b; k++) {
Modulo s = a[j + k + 0], t = a[j + k + b] * wn;
a[j + k] = s + t;
a[j + k + b] = s - t;
wn = wn * w;
}
}
}
if (inverse) {
Modulo v = Modulo(n).inv();
a *= v;
}
return a;
}
Vector<double> convolve(Vector<double> a, Vector<double> b) {
if (a.size() == 0 || b.size() == 0)
return Vector<double>();
int s = a.size() + b.size() - 1, t = std::pow(2, std::ceil(std::log2(s)));
a.resize(t);
b.resize(t);
Vector<std::complex<double>> A = fft(a), B = fft(b);
A *= B;
A = fft(A, true);
a.resize(s);
for (int i = 0; i < s; i++)
a[i] = A[i].real();
return a;
}
Vector<int> convolve(Vector<int> a, Vector<int> b) {
return convolve(Vector<double>(a), Vector<double>(b)) + 0.5;
}
Vector<Modulo> convolve(Vector<Modulo> a, Vector<Modulo> b) {
if (a.size() == 0 || b.size() == 0)
return Vector<Modulo>();
int s = a.size() + b.size() - 1, t = std::pow(2, std::ceil(std::log2(s)));
a.resize(t);
b.resize(t);
Vector<Modulo> A = ntt(a), B = ntt(b);
A *= B;
a = ntt(A, true);
a.resize(s);
return a;
}
// MultipleVector class need Vector, Modulo class
class MultipleVector {
Vector<Modulo> vfact, ifact, pows;
Modulo p;
public:
MultipleVector(int n = 0, int _p = 1)
: vfact(Vector<Modulo>(1, 1)), ifact(Vector<Modulo>(1, 1)),
pows(Vector<Modulo>(1, 1)), p(_p) {
resize(n);
}
void resize(int n) {
if (vfact.size() >= n)
return;
int s = vfact.size();
vfact.resize(n + 1);
for (int i = s; i <= n; i++)
vfact[i] = i * vfact[i - 1];
ifact.resize(n + 1);
ifact[n] = vfact[n].inv();
for (int i = n; i > s; i--)
ifact[i - 1] = i * ifact[i];
pows.resize(n + 1);
for (int i = s; i <= n; i++)
pows[i] = p * pows[i - 1];
}
Modulo fact(Modulo n) {
resize(n.val());
return vfact[n.val()];
}
Vector<Modulo> facts(Modulo n) {
resize(n.val());
return vfact[{0, n.val(), 1}];
}
Modulo factinv(Modulo n) {
resize(n.val());
return ifact[n.val()];
}
Vector<Modulo> factinvs(Modulo n) {
resize(n.val());
return ifact[{0, n.val(), 1}];
}
Modulo power(Modulo n) {
resize(n.val());
return pows[n.val()];
}
Vector<Modulo> powers(Modulo n) {
resize(n.val());
return pows[{0, n.val(), 1}];
}
Modulo parm(Modulo n, Modulo r) {
if (n < r)
return Modulo();
resize(n.val());
return vfact[n.val()] * ifact[(n - r).val()];
}
Modulo comb(Modulo n, Modulo r) {
if (n < r)
return Modulo();
resize(n.val());
return vfact[n.val()] * ifact[(n - r).val()] * ifact[r.val()];
}
Modulo homo(Modulo n, Modulo r) { return comb(n + r - 1, r); }
};
// Eratos class need Vector class
class Eratos {
Vector<int> divs, prms, ords;
int order_max;
public:
Eratos(int n = 0) : order_max(0) { resize(n); }
int size() const { return divs.size(); }
void resize(int n) {
if (size() >= n)
return;
int m = size();
divs.resize(n + 1);
for (int i = m; i < 2; i++)
if (i < size())
divs[i] = -1;
int r = std::sqrt(n - 1) + 1;
for (int i = 2; i < r; i++)
if (divs[i] == 0)
for (int j = std::max((m - 1) / i + 1, (int)2) * i; j <= n; j += i)
divs[j] = (divs[j] == 0 ? i : divs[j]);
for (int i = m; i <= n; i++)
if (divs[i] == 0)
prms.pub(i);
ords.resize(n + 1);
for (int i = m; i <= n; i++)
ords[i] = (divs[i] == 0 ? ++order_max : 0);
}
Vector<int> divisors() const { return divs; }
Vector<int> primes() const { return prms; }
Vector<int> orders() const { return ords; }
};
// Unionfind class need Vector class
template <typename T> class Unionfind {
Vector<int> p;
Vector<T> w;
int sign(int x) { return (x > 0) - (x < 0); }
int get(int x) {
if (p[x] == (x + 1))
return x + 1;
else {
int parent = sign(p[x]) * get(abs(p[x]) - 1);
w[x] += w[abs(p[x]) - 1];
return p[x] = parent;
}
}
void get(int &x, int &y) {
x = get(x);
y = get(y);
}
int weight(int x) {
get(x);
return w[x];
}
public:
Unionfind(int n = 0) { resize(n); }
void resize(const int &n) {
p.resize(n);
for (int i = w.size(); i < p.size(); i++)
p[i] = i + 1;
w.resize(n);
}
int size() const { return p.size(); }
bool unite(int x, int y, T vv = T()) {
if (vv < 0) {
std::swap(x, y);
vv *= -1;
}
vv += weight(x) - weight(y);
get(x, y);
if (abs(x) == abs(y))
return vv == weight(x) - weight(y);
p[abs(y) - 1] = x * sign(y);
w[abs(y) - 1] = vv;
return true;
}
bool separate(int x, int y, T vv = T()) {
if (vv < 0) {
std::swap(x, y);
vv *= -1;
}
vv += weight(x) - weight(y);
get(x, y);
if (abs(x) == abs(y))
return vv == weight(x) - weight(y);
p[abs(y) - 1] = -x * sign(y);
w[abs(y) - 1] = vv;
return true;
}
int same(int x, int y) {
get(x, y);
return (x == y) - (x == -y);
}
Vector<int> same(int x) {
Vector<int> v(size());
for (int i = 0; i < size(); i++)
v[i] = same(x, i);
return v;
}
T diff(int x, int y) { return sign(same(x, y)) * (weight(y) - weight(x)); }
Vector<T> diff(int x) {
Vector<int> v(size());
for (int i = 0; i < size(); i++)
v[i] = diff(x, i);
return v;
}
};
// Graph class need Vector class
template <typename T> struct Edge {
int from, to;
T cost;
Edge(int f = 0, int t = 0, T c = T()) : from(f), to(t), cost(c) {}
};
template <typename T> std::istream &operator>>(std::istream &i, Edge<T> &e) {
i >> e.from >> e.to >> e.cost;
return i;
}
template <typename T>
std::ostream &operator<<(std::ostream &o, const Edge<T> &e) {
return o << e.from << ' ' << e.to << ' ' << e.cost;
}
template <typename T> class Graph {
public:
Vector<Edge<T>> edge;
Vector<Vector<int>> node;
Graph(int n = 0) { resize(n); }
void resize(int n) { node.resize(n); }
void clear() {
edge = Vector<Edge<T>>();
node = Vector<Vector<int>>(nodes());
}
int edges() const { return edge.size(); }
int nodes() const { return node.size(); }
virtual int add(int from, int to, T cost) = 0;
Vector<T> dijkstra(int start) {
Vector<T> d(nodes(), std::numeric_limits<T>::max());
std::priority_queue<std::pair<T, int>, std::vector<std::pair<T, int>>,
std::greater<std::pair<T, int>>>
s;
d[start] = 0;
s.emplace(d[start], start);
while (!s.empty()) {
T dist = s.top().first;
int from = s.top().second;
s.pop();
if (d[from] < dist)
continue;
for (int id : node[from]) {
int to = edge[id].from ^ edge[id].to ^ from;
if (d[from] + edge[id].cost < d[to]) {
d[to] = d[from] + edge[id].cost;
s.emplace(d[to], to);
}
}
}
return d;
}
};
// Undigraph class need Vector, Graph class
template <typename T> class Undigraph : public Graph<T> {
Vector<int> brgs, crus, lows, ords;
bool lowlinked;
int lowlink_dfs(int from, int k, int parent) {
ords[from] = lows[from] = k++;
bool is_crunode = false;
int cnt = 0;
for (int id : node[from]) {
int to = edge[id].from ^ edge[id].to ^ from;
if (ords[to] == -1) {
cnt++;
k = lowlink_dfs(to, k, from);
lows[from] = std::min(lows[from], lows[to]);
is_crunode |= parent != -1 && lows[to] >= ords[from];
if (ords[from] < lows[to])
brgs.pub(id);
} else if (to != parent)
lows[from] = std::min(lows[from], lows[to]);
}
is_crunode |= parent == -1 && cnt > 1;
if (is_crunode)
crus.pub(from);
return k;
}
void lowlink() {
brgs = Vector<int>();
crus = Vector<int>();
ords.assign(this->nodes(), -1), lows.assign(this->nodes(), -1);
int k = 0;
for (int i = 0; i < this->nodes(); i++)
if (ords[i] == -1)
k = lowlink_dfs(i, k, -1);
lowlinked = true;
}
public:
using Graph<T>::edge;
using Graph<T>::node;
Undigraph(int n = 0) : Graph<T>(n) { lowlinked = false; }
int add(int from, int to, T cost = 1) {
int id = this->edges();
node[from].pub(id);
node[to].pub(id);
edge.pub(Edge<T>(from, to, cost));
return id;
}
void reset_lowlink() { lowlink(); }
Vector<int> bridges() {
if (!lowlinked)
lowlink();
return brgs;
}
Vector<int> crunodes() {
if (!lowlinked)
lowlink();
return crus;
}
T prim(int start = 0) {
Vector<std::pair<T, std::pair<int, int>>> cft;
T total = 0;
Vector<int> used(this->nodes(), 0);
std::priority_queue<std::pair<T, std::pair<int, int>>,
std::vector<std::pair<T, std::pair<int, int>>>,
std::greater<std::pair<T, std::pair<int, int>>>>
s;
s.emplace(std::make_pair(0, std::make_pair(-1, start)));
while (!s.empty()) {
T cost = s.top().first;
int fromfrom = s.top().second.first, from = s.top().second.second;
s.pop();
if (used[from])
continue;
used[from] = true;
total += cost;
if (fromfrom > -1)
cft.pub(std::make_pair(cost, std::make_pair(fromfrom, from)));
for (int id : node[from]) {
int to = edge[id].from ^ edge[id].to ^ from;
s.emplace(std::make_pair(edge[id].cost, std::make_pair(from, to)));
}
}
this->clear();
for (std::pair<T, std::pair<int, int>> e : cft)
add(e.second.first, e.second.second, e.first);
return total;
}
};
// Forest class need Vector, Graph, Undigraph class
template <typename T> class Forest : public Undigraph<T> {
public:
Vector<int> root, parent, treesize, depth;
Vector<T> dist;
Vector<Vector<int>> children;
using Undigraph<T>::edge;
using Undigraph<T>::node;
using Undigraph<T>::resize;
using Undigraph<T>::edges;
using Undigraph<T>::nodes;
Forest(int n = 0) : Undigraph<T>(n) { initialize(); }
void initialize() {
root.assign(nodes(), -1);
parent.assign(nodes(), -1);
treesize.assign(nodes(), 1);
depth.assign(nodes(), 0);
dist.assign(nodes(), 0);
children.assign(nodes(), Vector<int>());
}
private:
void dfs(int from) {
for (int &id : node[from]) {
if (from == edge[id].from)
std::swap(edge[id].from, edge[id].to);
int to = edge[id].from;
if (root[to] != -1)
continue;
root[to] = root[from];
parent[to] = from;
depth[to] = depth[from] + 1;
dist[to] = dist[from] + edge[id].cost;
children[from].pub(to);
dfs(to);
treesize[from] += treesize[to];
}
}
public:
void setTreeRoot(int n) {
initialize();
root[n] = n;
dfs(n);
}
void setForestRoot() {
initialize();
for (int n = 0; n < nodes(); n++)
if (root[n] == -1) {
root[n] = n;
dfs(n);
};
}
T diameter(int n = 0) {
setTreeRoot(n);
int terminal = dist.argmax();
setTreeRoot(terminal);
return dist.max();
}
};
// Digraph class need Vector, Graph class
template <typename T> class Digraph : public Graph<T> {
Vector<Vector<int>> rev_node;
Vector<Edge<T>> rev_edge;
Vector<int> strong_edgeid, weak_edgeid, strong_id, ords;
bool scced;
void scc_dfs(int from) {
if (strong_id[from] == -1)
return;
strong_id[from] = -1;
for (int id : node[from]) {
int to = edge[id].from ^ edge[id].to ^ from;
scc_dfs(to);
}
ords.pub(from);
}
void scc_rdfs(int from, int cnt) {
if (strong_id[from] != -1)
return;
strong_id[from] = cnt;
for (int id : rev_node[from]) {
int to = rev_edge[id].from ^ rev_edge[id].to ^ from;
if (strong_id[to] == -1) {
strong_edgeid.pub(id);
scc_rdfs(to, cnt);
} else if (strong_id[to] == cnt)
strong_edgeid.pub(id);
else if (strong_id[to] < cnt)
weak_edgeid.pub(id);
}
}
public:
using Graph<T>::edge;
using Graph<T>::node;
Digraph(int n = 0) : Graph<T>(n), scced(false) {}
int add(int from, int to, T cost = 1) {
int id = this->edges();
node[from].pub(id);
edge.pub(Edge<T>(from, to, cost));
return id;
}
Digraph<T> reversed() const {
Digraph<T> r(this->edges());
for (Edge<T> e : edge)
r.add(e.to, e.from, e.cost);
return r;
}
void scc() {
strong_edgeid = Vector<int>();
weak_edgeid = Vector<int>();
strong_id.assign(this->nodes(), 0);
ords = Vector<int>(this->nodes());
rev_node = Vector<Vector<int>>(this->nodes());
rev_edge = Vector<Edge<T>>(this->edges());
for (int id = 0; id < this->edges(); id++) {
rev_node[edge[id].to].pub(id);
rev_edge[id] = Edge<T>(edge[id].to, edge[id].from, edge[id].cost);
}
for (int from = 0; from < this->nodes(); from++)
scc_dfs(from);
ords.reverse();
int cnt = 0;
for (int from : ords)
if (strong_id[from] == -1) {
scc_rdfs(from, cnt);
cnt++;
}
Vector<Edge<T>> strong_edge;
for (int id : strong_edgeid)
strong_edge.pub(edge[id]);
this->clear();
for (Edge<T> e : strong_edge)
add(e.from, e.to, e.cost);
scced = true;
}
Vector<int> weakid() {
if (!scced)
scc();
return weak_edgeid;
};
Vector<int> stronggroup() {
if (!scced)
scc();
return strong_id;
}
Vector<T> bellman(int start) {
Vector<T> d(this->nodes(), std::numeric_limits<T>::max());
d[start] = 0;
bool negloop = false;
Vector<int> updating(1, start);
for (int i = 0; i < this->nodes() && updating.size() > 0; i++) {
Vector<int> toUpdate;
for (int from : updating) {
for (int id : node[from]) {
int to = edge[id].from ^ edge[id].to ^ from;
if (d[to] > d[from] + edge[id].cost) {
d[to] = d[from] + edge[id].cost;
toUpdate.pub(to);
if (i == this->nodes() - 1)
d[to] = std::numeric_limits<T>::min();
negloop = true;
}
}
}
updating = toUpdate;
}
if (negloop) {
for (int i = 0; i < this->nodes() && updating.size() > 0; i++) {
Vector<int> toUpdate;
for (int from : updating) {
for (int id : node[from]) {
int to = edge[id].from ^ edge[id].to ^ from;
if (d[to] != std::numeric_limits<T>::min()) {
d[to] = std::numeric_limits<T>::min();
toUpdate.pub(to);
}
}
}
updating = toUpdate;
}
}
return d;
}
Vector<int> topsort() {
Vector<int> to_node(this->nodes(), 0);
for (Edge<T> e : edge)
to_node[e.to]++;
Vector<int> sorted;
for (int i = 0; i < this->nodes(); i++)
if (to_node[i] == 0)
sorted.pub(i);
for (int i = 0; i < sorted.size(); i++)
for (int id : node[sorted[i]]) {
if (--to_node[edge[id].to] == 0)
sorted.pub(edge[id].to);
}
if (sorted.size() != this->nodes())
return Vector<int>();
return sorted;
}
};
// math function for Vector, Matrix, Modulo class
template <typename T> T sign(const T &x) { return (x > 0) - (x < 0); }
template <typename T> T abs(const T &x) { return x * sign(x); }
template <typename T> T power(T x, int y) {
T r = x * 0 + 1;
while (y > 0) {
if (y & 1)
r *= x;
x *= x;
y /= 2;
}
return r;
}
bool is_power(int n, int m) {
return n == power(llround(std::pow(n, (double)+1 / m)), m);
}
int _gcd(const int &a, const int &b) { return b ? _gcd(b, a % b) : a; }
int gcd(const int &a, const int &b) {
return _gcd(std::max(a, b), std::min(a, b));
}
int lcm(const int &a, const int &b) { return a / gcd(a, b) * b; }
bool is_prime(int n) {
int m = std::sqrt(n - 1) + 1;
for (int i = 2; i < m + 1; i++)
if (n % i == 0)
return false;
return n > 1;
}
int fact(int n) {
int v = 1;
for (int i = 1; i < n + 1; i++)
v *= i;
return v;
}
Modulo fact(Modulo n) {
Modulo v = 1;
for (int i = 1; i < n + 1; i++)
v *= i;
return v;
}
int parm(int n, int r) {
int v = 1;
for (int i = n - r + 1; i < n + 1; i++)
v *= i;
return v;
}
Modulo parm(Modulo n, Modulo r) {
Modulo v = 1;
for (int i = n.val() - r.val() + 1; i < n.val() + 1; i++)
v *= i;
return v;
}
int comb(int n, int r) {
int v = 1;
r = std::min(r, n - r);
for (int i = 0; i < r; i++) {
v *= n - i;
v /= i + 1;
}
return v;
}
Modulo comb(Modulo n, Modulo r) {
Modulo p = 1, q = 1;
r = std::min(r, n - r);
for (int i = 0; i < r; i++) {
p *= n - i;
q *= i + 1;
}
return p / q;
}
int homo(int m, int n) { return comb(m + n - 1, n); }
Modulo homo(Modulo m, Modulo n) { return comb(m + n - 1, n); }
// ex. function_find(fname,0,1024,'u',100,output)
#define function_find(FUNCTION_INT_TO_VALUE, INT_RANGE_MIN, INT_RANGE_MAX, \
CHAR_KIND, VALUE_TARGET, INT_AND_OUTPUT) \
{ \
int left = INT_RANGE_MIN - 1; \
int right = INT_RANGE_MAX + 1; \
bool outleft = (CHAR_KIND == 'd' || CHAR_KIND == 'U'); \
int getmin = (CHAR_KIND == 'u' || CHAR_KIND == 'd') ? 1 : -1; \
while (right - left > 1) { \
int mid = left + (right - left) / 2; \
bool OK = FUNCTION_INT_TO_VALUE(mid) * getmin >= VALUE_TARGET * getmin; \
if (outleft == OK) \
left = mid; \
else \
right = mid; \
} \
INT_AND_OUTPUT = outleft ? left : right; \
}
// BinaryIndexedTree class need Vector class
#define BITCalc(OP) \
BinaryIndexedTree<T> operator OP##=(const T &v) { \
if (range.first + 1 == range.second) \
for (int i = range.first; i < size(); i |= (i + 1)) \
t1[i] OP## = v; \
else \
for (int i = range.first; i < size(); i |= (i + 1)) { \
t1[i] OP## = -v * (range.first - 1); \
t2[i] OP## = v; \
} \
for (int i = range.second; i < size(); i |= (i + 1)) { \
t1[i] OP## = v * (range.second - 1); \
t2[i] OP## = -v; \
} \
return *this; \
}
template <typename T> class BinaryIndexedTree {
Vector<T> t1, t2;
std::pair<int, int> range;
public:
T sum(int x) {
T v = T();
for (int i = x; i >= 0; i = (i & (i + 1)) - 1) {
v += t1[i] + t2[i] * x;
}
return v;
}
T sum(int l, int r) { return sum(r - 1) - sum(l - 1); }
T get(int x) { return sum(x, x + 1); }
void resize(int n) {
t1.resize(n);
t2.resize(n);
}
int size() const { return t1.size(); }
Vector<T> firstVector() const { return t1; }
Vector<T> secondVector() const { return t2; }
BinaryIndexedTree(int n = 0) : range(std::make_pair(0, 0)) { resize(n); }
BinaryIndexedTree(const BinaryIndexedTree &bit)
: t1(bit.firstVector()), t2(bit.secondVector()),
range(std::make_pair(0, -1)) {
resize(bit.size());
}
BinaryIndexedTree<T> &operator=(const BinaryIndexedTree<T> &bit) {
resize(bit.size());
t1 = bit.firstVector();
t2 = bit.secondVector();
return *this;
}
T operator[](int i) const { return get(i); }
BinaryIndexedTree<T> &operator[](std::initializer_list<int> l) {
if (l.size() == 1) {
range.first = *l.begin();
range.second = (*l.begin()) + 1;
}
if (l.size() == 2) {
range.first = *l.begin();
range.second = (*(l.begin() + 1) < 0 ? *(l.begin() + 1) + size() + 1
: *(l.begin() + 1));
}
return *this;
}
BITCalc(+) BITCalc(-) T sum() { return sum(range.first, range.second); }
BinaryIndexedTree<T> operator=(const T &v) {
for (int i = range.first; i < range.second; i++) {
operator[]({i});
operator+=(-get(i) + v);
}
return *this;
}
Vector<T> toVector() {
Vector<T> v(size());
for (int i = 0; i < size(); i++)
v[i] = get(i);
return v;
}
};
class Input {
public:
template <typename T> void input_integer(T &var) noexcept {
var = 0;
T sign = 1;
int cc = getchar_unlocked();
for (; cc < '0' || '9' < cc; cc = getchar_unlocked())
if (cc == '-')
sign = -1;
for (; '0' <= cc && cc <= '9'; cc = getchar_unlocked())
var = (var << 3) + (var << 1) + cc - '0';
var = var * sign;
}
Input &operator>>(int32_t &var) {
input_integer(var);
return *this;
}
Input &operator>>(int64_t &var) {
input_integer(var);
return *this;
}
Input &operator>>(std::string &var) {
int c = getchar_unlocked();
while (!(0x21 <= c && c <= 0x7E))
c = getchar_unlocked();
while (0x21 <= c && c <= 0x7E) {
var.push_back(c);
c = getchar_unlocked();
}
return *this;
}
};
Input input;
// BIT^2, graph
// argofsortup
// 10^5 -> NlogN, 3000 -> N^2, 200 -> N^3, 50 -> N^4, 20 -> 2^N
WRITE_FUNCTION_UNDER_HERE
int32_t main() {
INIT;
in(int, n, m);
VPII py(m);
fou(i, 0, py.size()) { input >> py[i].fi >> py[i].se; }
VI order(m);
order.iota();
order = separate((unite(py, order)).sortuped()).se;
py.sortup();
py[0].se = 1;
fou(i, 1, py.size()) {
if (py[i].fi == py[i - 1].fi) {
py[i].se = py[i - 1].se + 1;
} else {
py[i].se = 1;
}
}
py = separate((unite(order, py)).sortuped()).se;
fou(i, 0, py.size()) {
String pref = py[i].fi;
while (pref.size() < 6)
pref.insert(0, '0');
String year = py[i].se;
while (year.size() < 6)
year.insert(0, '0');
out(pref + year);
}
} | #pragma GCC optimize( \
"O3,Ofast,inline,fast-math,unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define int int64_t
#define double long double
#define INIT \
std::ios_base::sync_with_stdio(0); \
std::cin.tie(0); \
std::cout << std::fixed << std::setprecision(15);
#define WRITE_FUNCTION_UNDER_HERE DEFALLTYPE(VDEF) DEFALLTYPE(PDEF3)
const int MOD = 1e9 + 7;
using namespace std;
const int MAX = std::numeric_limits<int>::max();
const int MIN = std::numeric_limits<int>::min();
const double EPS = 1e-7;
#define fou(i, a, n) for (int i = a; i < n; i++)
#define fod(i, a, n) for (int i = n - 1; i >= a; i--)
#define tra(e, v) for (auto &e : v)
#define elif(c) else if (c)
#define fi first
#define se second
#define fir fi
#define sec se.fi
#define thi se.se
#define firs fi
#define seco sec
#define thir thi.fi
#define four thi.se
#define DEFALLTYPE(XDEF) \
XDEF(int, I) \
XDEF(double, D) XDEF(char, C) XDEF(String, S) XDEF(bool, B) XDEF(Modulo, M)
#define VDEF(t, T) \
typedef Vector<t> V##T; \
typedef Vector<V##T> VV##T; \
typedef Vector<VV##T> VVV##T;
#define PDEF(x, X, y, Y, z, Z, w, W) \
typedef std::pair<x, y> P##X##Y; \
VDEF(P##X##Y, P##X##Y) typedef std::pair<x, std::pair<y, z>> P##X##Y##Z; \
VDEF(P##X##Y##Z, P##X##Y##Z) \
typedef std::pair<x, std::pair<y, std::pair<z, w>>> P##X##Y##Z##W; \
VDEF(P##X##Y##Z##W, P##X##Y##Z##W)
#define PDEF1(y, Y, z, Z, w, W) \
PDEF(int, I, y, Y, z, Z, w, W) \
PDEF(double, D, y, Y, z, Z, w, W) PDEF(char, C, y, Y, z, Z, w, W) \
PDEF(String, S, y, Y, z, Z, w, W) PDEF(bool, B, y, Y, z, Z, w, W) \
PDEF(Modulo, M, y, Y, z, Z, w, W)
#define PDEF2(z, Z, w, W) \
PDEF1(int, I, z, Z, w, W) \
PDEF1(double, D, z, Z, w, W) PDEF1(char, C, z, Z, w, W) \
PDEF1(String, S, z, Z, w, W) PDEF1(bool, B, z, Z, w, W) \
PDEF1(Modulo, M, z, Z, w, W)
#define PDEF3(w, W) \
PDEF2(int, I, w, W) \
PDEF2(double, D, w, W) PDEF2(char, C, w, W) PDEF2(String, S, w, W) \
PDEF2(bool, B, w, W) PDEF2(Modulo, M, w, W)
// in, out
#define in(T, ...) \
T __VA_ARGS__; \
_in(__VA_ARGS__)
void _in() {}
template <typename Hd, typename... Tl> void _in(Hd &hd, Tl &&...tl) {
std::cin >> hd;
_in(std::forward<Tl>(tl)...);
}
void out() { std::cout << '\n'; }
template <typename T> void out(const T &a) { std::cout << a << '\n'; }
template <typename Hd, typename... Tl> void out(const Hd &hd, const Tl &...tl) {
std::cout << hd << ' ';
out(tl...);
}
// std::pair io,calc
#define PairCalc(OP) \
template <typename T, typename U, typename V, typename W> \
std::pair<T, U> operator OP(const std::pair<T, U> &l, \
const std::pair<V, W> &r) { \
return std::make_pair(l.first OP r.first, l.second OP r.second); \
} \
template <typename T, typename U, typename V, typename W> \
std::pair<T, U> operator OP##=(std::pair<T, U> &l, \
const std::pair<V, W> &r) { \
return l = l OP r; \
}
template <typename T, typename U>
std::istream &operator>>(std::istream &i, std::pair<T, U> &p) {
i >> p.first >> p.second;
return i;
}
template <typename T, typename U>
std::ostream &operator<<(std::ostream &o, const std::pair<T, U> &p) {
return o << p.first << ' ' << p.second;
}
PairCalc(+) PairCalc(-) PairCalc(*) PairCalc(/) PairCalc(%) PairCalc(<<)
PairCalc(>>) PairCalc(&) PairCalc(|)
PairCalc(^) template <typename T, typename U>
std::pair<T, U> mp(const T &t, const U &u) {
return std::make_pair(t, u);
}
template <typename T, typename U, typename V>
std::pair<T, std::pair<U, V>> mp(const T &t, const U &u, const V &v) {
return std::make_pair(t, std::make_pair(u, v));
}
template <typename T, typename U, typename V, typename W>
std::pair<T, std::pair<U, std::pair<V, W>>> mp(const T &t, const U &u,
const V &v, const W &w) {
return std::make_pair(t, std::make_pair(u, std::make_pair(v, w)));
}
// Slice class, Vector class
struct Slice {
int first = 0;
int last = -1;
int step = 1;
Slice(int f, int l = -1, int s = 1) : first(f), last(l), step(s) {}
Slice(std::initializer_list<int> l) {
if (l.size() != 3)
return;
first = *l.begin();
last = *(l.begin() + 1);
step = *(l.begin() + 2);
}
};
#define VecCalc(OP) \
Vector<T> operator OP(const Vector<T> &r) const { \
Vector<T> v(std::min(size(), r.size())); \
for (int i = 0; i < v.size(); i++) \
v[i] = value[i] OP r[i]; \
return v; \
} \
Vector<T> operator OP(const T &r) const { \
Vector<T> v(size()); \
for (int i = 0; i < size(); i++) \
v[i] = value[i] OP r; \
return v; \
} \
Vector<T> operator OP##=(const Vector<T> &r) { return *this = *this OP r; } \
Vector<T> operator OP##=(const T &r) { return *this = *this OP r; }
#define VecComp(OP) \
Vector<int> operator OP(const Vector<T> &r) const { \
Vector<int> v(std::min(size(), r.size())); \
for (int i = 0; i < v.size(); i++) \
v[i] = value[i] OP r[i]; \
return v; \
} \
Vector<int> operator OP(const T &r) const { \
Vector<int> v(size()); \
for (int i = 0; i < size(); i++) \
v[i] = value[i] OP r; \
return v; \
}
#define VVCalc(OP) \
template <typename T, typename U> \
Vector<Vector<T>> operator OP(Vector<Vector<T>> l, const U &r) { \
for (Vector<T> & e : l) \
e OP## = r; \
return l; \
} \
template <typename T, typename U> \
Vector<Vector<T>> operator OP##=(Vector<Vector<T>> &l, const U &r) { \
return l = l OP r; \
}
#define VVComp(OP) \
template <typename T, typename U> \
Vector<Vector<int>> operator OP(const Vector<Vector<T>> &l, const U &r) { \
Vector<Vector<int>> v(l.size()); \
for (int i = 0; i < l.size(); i++) \
v[i] = l[i] OP r; \
return v; \
}
template <typename T> class Vector {
std::vector<T> value;
public:
Vector(int s = 0, T v = T()) {
if (s >= 0)
assign(s, v);
else {
assign(-s, v);
for (T &e : value)
std::cin >> e;
}
}
Vector(const std::initializer_list<T> &l) { value = std::vector<T>{l}; }
template <typename U> Vector(const Vector<U> &v) {
resize(v.size());
for (int i = 0; i < size(); i++)
value[i] = v[i];
}
Vector(const std::vector<T> &v) { value = v; }
int size() const { return value.size(); }
T operator[](int i) const { return value[i]; }
T &operator[](int i) { return value[i]; }
Vector<T> operator[](Slice s) const {
s.last = (s.last < 0 ? s.last + size() + 1 : s.last);
Vector<T> v;
for (int i = s.first; i < s.last; i += s.step)
v.pub(value[i]);
return v;
}
Vector<T> &operator=(const Vector<T> &v) {
resize(v.size());
for (int i = 0; i < size(); i++)
value[i] = v[i];
return *this;
}
Vector<T> operator+() const { return *this; }
Vector<T> operator-() const {
Vector<T> v(value.size());
for (int i = 0; i < size(); i++)
v[i] = -value[i];
return v;
}
Vector<T> operator++() {
for (T &e : value)
e++;
return *this;
}
Vector<T> operator--() {
for (T &e : value)
e--;
return *this;
}
Vector<T> operator++(int32_t) {
Vector<T> v = *this;
for (T &e : value)
e++;
return v;
}
Vector<T> operator--(int32_t) {
Vector<T> v = *this;
for (T &e : value)
e--;
return v;
}
std::vector<T> stdVector() const { return value; }
std::vector<T> &stdVector() { return value; }
void out() {
for (const T &e : value)
std::cout << e << '\n';
}
void iota() {
for (int i = 0; i < size(); i++)
value[i] = i;
}
Vector<T> iotaed() const {
Vector<T> r(*this);
r.iota();
return r;
}
T last() const { return value[size() - 1]; }
T &last() { return value[size() - 1]; }
auto begin() { return value.begin(); }
auto end() { return value.end(); }
auto begin() const { return value.begin(); }
auto end() const { return value.end(); }
T sum(int l = 0, int r = -1) const {
T v = T();
r = (r < 0 ? r + size() + 1 : r);
for (int i = l; i < r; i++)
v += value[i];
return v;
}
T prod(int l = 0, int r = -1) const {
T v = T() + 1;
r = (r < 0 ? r + size() + 1 : r);
for (int i = l; i < r; i++)
v *= value[i];
return v;
}
T xorsum(int l = 0, int r = -1) const {
T v = T();
r = (r < 0 ? r + size() + 1 : r);
for (int i = l; i < r; i++)
v ^= value[i];
return v;
}
int argmin() const { return std::min_element(begin(), end()) - begin(); }
int argmax() const { return std::max_element(begin(), end()) - begin(); }
T min() const { return value[argmin()]; }
T max() const { return value[argmax()]; }
T dot(const Vector<T> &v) const {
T r = T();
for (int i = 0; i < std::min(size(), v.size()); i++)
r += value[i] * v[i];
return r;
}
void resize(int s, T v = T()) { value.resize(s, v); }
void assign(int s, const T &v) { value.assign(s, v); }
void pub(const T &v) { value.push_back(v); }
void pub(const Vector<T> &v) { value.insert(end(), v.begin(), v.end()); }
void insert(int i, const T &v) { value.insert(begin() + i, v); }
void insert(int i, const Vector<T> &v) {
value.insert(begin() + i, v.begin(), v.end());
}
void pob() { value.pop_back(); }
void erase(int i, int j = -1) {
if (j < 0)
value.erase(begin() + i);
else
value.erase(begin() + i, begin() + j);
}
void erase_unique() { value.erase(std::unique(begin(), end()), end()); }
void reverse() { std::reverse(begin(), end()); }
void rotatedown(int i) {
if (i > 0)
std::rotate(begin(), begin() + i, end());
}
void rotateup(int i) {
if (i > 0)
std::rotate(value.rbegin(), value.rbegin() + i, value.rend());
}
void sortup() { std::sort(begin(), end()); }
void sortdown() { std::sort(value.rbegin(), value.rend()); }
void cumsum() {
for (int i = 0; i < size() - 1; i++)
value[i + 1] += value[i];
}
void sumdiff() {
for (int i = size() - 2; i >= 0; i--)
value[i + 1] -= value[i];
}
T cumsumpart(int l, int r) const {
return value[r - 1] - (l = 0 ? 0 : value[l - 1]);
}
void cumxorsum() {
for (int i = 0; i < size() - 1; i++)
value[i + 1] ^= value[i];
}
void xorsumdiff() {
for (int i = size() - 2; i >= 0; i--)
value[i + 1] ^= value[i];
}
T cumxorsumpart(int l, int r) const {
return value[r - 1] ^ (l = 0 ? 0 : value[l - 1]);
}
void bucketsortup() {
int m = min();
Vector<int> b(max() - m + 1);
for (int e : value)
b[e - m]++;
b.cumsum();
for (int i = 0; i < b.size(); i++)
for (int j = (i == 0 ? 0 : b[i - 1]); j < b[i]; j++)
value[j] = m + i;
}
void bucketsortdown() {
bucketsortup();
reverse();
}
void compress() {
Vector<T> u(value);
u.sortup();
u.erase_unique();
std::unordered_map<T, int> m;
for (int i = 0; i < u.size(); i++)
m[u[i]] = i;
for (int i = 0; i < size(); i++)
value[i] = m[value[i]];
}
void argofsortup() {
Vector<std::pair<T, T>> p(size());
for (int i = 0; i < size(); i++)
p[i] = std::make_pair(value[i], i);
p.sortup();
for (int i = 0; i < size(); i++)
value[i] = p[i].second;
}
void argofsortdown() {
Vector<std::pair<T, T>> p(size());
for (int i = 0; i < size(); i++)
p[i] = std::make_pair(value[i], i);
p.sortdown();
for (int i = 0; i < size(); i++)
value[i] = p[i].second;
}
int findupgeq(const T &v) {
return std::lower_bound(begin(), end(), v) - begin();
}
int findupleq(const T &v) {
return std::upper_bound(begin(), end(), v) - begin() - 1;
}
int upcount(const T &v) { return findupleq(v) - findupgeq(v) + 1; }
int finddowngeq(const T &v) {
return size() -
(std::lower_bound(value.rbegin(), value.rend(), v) -
value.rbegin()) -
1;
}
int finddownleq(const T &v) {
return size() -
(std::upper_bound(value.rbegin(), value.rend(), v) - value.rbegin());
}
int downcount(const T &v) { return finddowngeq(v) - finddownleq(v) + 1; }
VecCalc(+) VecCalc(-) VecCalc(*) VecCalc(/) VecCalc(%) VecCalc(<<) VecCalc(>>)
VecCalc(&) VecCalc(|) VecCalc(^) VecComp(==) VecComp(!=) VecComp(>=)
VecComp(<=) VecComp(>) VecComp(<) Vector<T> pubed(const T &v) const {
Vector<T> r(*this);
r.pub(v);
return r;
}
Vector<T> pubed(const Vector<T> &v) const {
Vector<T> r(*this);
r.pub(v);
return r;
}
Vector<T> inserted(int i, const T &v) const {
Vector<T> r(*this);
r.insert(i, v);
return r;
}
Vector<T> inserted(int i, const Vector<T> &v) const {
Vector<T> r(*this);
r.insert(i, v);
return r;
}
Vector<T> pobed() const {
Vector<T> r(*this);
r.pob();
return r;
}
Vector<T> erased(int i, int j = -1) const {
Vector<T> r(*this);
r.erase(i, j);
return r;
}
Vector<T> erase_uniqued() const {
Vector<T> r(*this);
r.erase_unique();
return r;
}
Vector<T> reversed() const {
Vector<T> r(*this);
r.reverse();
return r;
}
Vector<T> rotatedowned(int i) const {
Vector<T> r(*this);
r.rotatedown(i);
return r;
}
Vector<T> rotateuped(int i) const {
Vector<T> r(*this);
r.rotateup(i);
return r;
}
Vector<T> sortuped() const {
Vector<T> r(*this);
r.sortup();
return r;
}
Vector<T> sortdowned() const {
Vector<T> r(*this);
r.sortdown();
return r;
}
Vector<T> cumsumed() const {
Vector<T> r(*this);
r.cumsum();
return r;
}
Vector<T> sumdiffed() const {
Vector<T> r(*this);
r.sumdiff();
return r;
}
Vector<T> cumxorsumed() const {
Vector<T> r(*this);
r.cumxorsum();
return r;
}
Vector<T> xorsumdiffed() const {
Vector<T> r(*this);
r.xorsumdiff();
return r;
}
Vector<T> bucketsortuped() const {
Vector<T> r(*this);
r.bucketsortup();
return r;
}
Vector<T> bucketsortdowned() const {
Vector<T> r(*this);
r.bucketsortdown();
return r;
}
Vector<T> compressed() const {
Vector<T> r(*this);
r.compress();
return r;
}
Vector<T> argofsortuped() const {
Vector<T> r(*this);
r.argofsortup();
return r;
}
Vector<T> argofsortdowned() const {
Vector<T> r(*this);
r.argofsortdown();
return r;
}
};
VVCalc(+) VVCalc(-) VVCalc(*) VVCalc(/) VVCalc(%) VVCalc(<<) VVCalc(>>)
VVCalc(&) VVCalc(|) VVCalc(^) VVComp(==) VVComp(!=) VVComp(>=) VVComp(<=)
VVComp(>) VVComp(<) template <typename T, typename U>
Vector<std::pair<T, U>> unite(const Vector<T> &v, const Vector<U> &u) {
int s = std::min(v.size(), u.size());
Vector<std::pair<T, U>> r(s);
for (int i = 0; i < s; i++)
r[i] = std::make_pair(v[i], u[i]);
return r;
}
template <typename T, typename U>
std::pair<Vector<T>, Vector<U>> separate(const Vector<std::pair<T, U>> &p) {
Vector<T> v(p.size());
Vector<U> u(p.size());
for (int i = 0; i < p.size(); i++) {
v[i] = p[i].first;
u[i] = p[i].second;
}
return std::make_pair(v, u);
}
template <typename T> std::istream &operator>>(std::istream &i, Vector<T> &v) {
for (T &e : v)
i >> e;
return i;
}
template <typename T>
std::ostream &operator<<(std::ostream &o, const Vector<T> &v) {
if (v.size() == 0)
return o;
for (int i = 0; i < v.size() - 1; i++)
o << v[i] << ' ';
return o << v.last();
}
Vector<int> baseVector(int n, int b) {
Vector<int> v(64);
for (int &e : v) {
e = n % b;
n /= b;
}
return v;
}
int baseVectorValue(Vector<int> v, int b) {
int n = 0, m = 1;
for (int &e : v) {
n += e * m;
m *= b;
}
return n;
}
// Matrix class need Vector class
#define MatCalc(OP) \
Matrix<T> operator OP(const Matrix<T> &r) const { \
Matrix<T> v(std::min(size(), r.size())); \
for (int i = 0; i < v.size(); i++) \
v[i] = value[i] OP r[i]; \
return v; \
} \
Matrix<T> operator OP(const Vector<T> &r) const { \
Matrix<T> v(std::min(size(), r.size())); \
for (int i = 0; i < size(); i++) \
v[i] = value[i] OP r; \
return v; \
} \
Matrix<T> operator OP(const T &r) const { \
Matrix<T> v(size()); \
for (int i = 0; i < size(); i++) \
v[i] = value[i] OP r; \
return v; \
} \
Matrix<T> operator OP##=(const Matrix<T> &r) { return *this = *this OP r; } \
Matrix<T> operator OP##=(const Vector<T> &r) { return *this = *this OP r; } \
Matrix<T> operator OP##=(const T &r) { return *this = *this OP r; }
#define MatComp(OP) \
Matrix<int> operator OP(const Matrix<T> &r) const { \
Matrix<int> v(std::min(size(), r.size())); \
for (int i = 0; i < v.size(); i++) \
v[i] = value[i] OP r[i]; \
return v; \
} \
Matrix<int> operator OP(const Vector<T> &r) const { \
Matrix<int> v(size()); \
for (int i = 0; i < size(); i++) \
v[i] = value[i] OP r; \
return v; \
} \
Matrix<int> operator OP(const T &r) const { \
Matrix<int> v(size()); \
for (int i = 0; i < size(); i++) \
v[i] = value[i] OP r; \
return v; \
}
template <typename T> class Matrix {
Vector<Vector<T>> value;
public:
Matrix(int c = 0, int r = 0, T v = T()) {
if (c >= 0 && r >= 0)
assign(c, r, v);
else {
assign(-c, -r, v);
for (Vector<T> &e : value)
std::cin >> e;
}
}
Matrix(std::pair<int, int> p, T v = T()) {
if (p.first >= 0 && p.second >= 0)
assign(p.first, p.second, v);
else {
resize(-p.first, -p.second);
for (Vector<T> &e : value)
std::cin >> e;
}
}
Matrix(const std::initializer_list<std::initializer_list<T>> &l) {
value.resize(l.size());
for (int i = 0; i < size(); i++)
value[i] = *(l.begin() + i);
rect();
}
template <typename U> Matrix(const Matrix<U> &v) {
resize(v.size());
for (int i = 0; i < size(); i++)
value[i] = v[i];
}
Matrix(const Vector<Vector<T>> &v) {
value.resize(v.size());
for (int i = 0; i < size(); i++)
value[i] = v[i];
rect();
}
Matrix(const std::vector<std::vector<T>> &v) {
value.resize(v.size());
for (int i = 0; i < size(); i++)
value[i] = v[i];
rect();
}
void rect() {
Vector<T> v(size());
for (int i = 0; i < size(); i++)
v[i] = value[i].size();
resize(size(), v.max());
}
int size() const { return value.size(); }
std::pair<int, int> shape() const {
return std::make_pair(size(), size() == 0 ? 0 : value[0].size());
}
Vector<T> operator[](int i) const { return value[i]; }
Vector<T> &operator[](int i) { return value[i]; }
T operator[](std::pair<int, int> p) const { return value[p.first][p.second]; }
T &operator[](std::pair<int, int> p) { return value[p.first][p.second]; }
Matrix<T> operator[](Slice p) const { return value[p]; }
Matrix<T> operator[](std::pair<Slice, Slice> p) const {
p.first.last =
(p.first.last < 0 ? p.first.last + shape().first + 1 : p.first.last);
p.second.last = (p.second.last < 0 ? p.second.last + shape().second + 1
: p.second.last);
Matrix<T> v;
for (int i = p.first.first; i < p.first.last; i += p.first.step) {
Vector<T> u;
for (int j = p.second.first; j < p.second.last; j += p.second.step)
u.pub(value[i][j]);
v.vstack(u);
}
return v;
}
Matrix<T> &operator=(const Matrix<T> &v) {
value.resize(size());
for (int i = 0; i < v.size(); i++)
value[i] = v[i];
return *this;
}
Matrix<T> operator+() const { return *this; }
Matrix<T> operator-() const {
Matrix<T> v(value.size());
for (int i = 0; i < size(); i++)
v[i] = -value[i];
return v;
}
Matrix<T> operator++() {
for (Vector<T> &e : value)
e++;
return *this;
}
Matrix<T> operator--() {
for (Vector<T> &e : value)
e--;
return *this;
}
Matrix<T> operator++(int32_t) {
Matrix<T> v = *this;
for (Vector<T> &e : value)
e++;
return v;
}
Matrix<T> operator--(int32_t) {
Matrix<T> v = *this;
for (Vector<T> &e : value)
e--;
return v;
}
std::vector<std::vector<T>> stdVector() {
std::vector<std::vector<T>> v(size());
for (int i = 0; i < size(); i++)
v[i] = value[i].stdVector();
return v;
}
void out() {
for (const Vector<T> &e : value)
std::cout << e << '\n';
}
Vector<Vector<T>> vectorVector() { return value; }
Vector<T> last() const { return value[size() - 1]; }
Vector<T> &last() { return value[size() - 1]; }
Vector<T> vector() const {
Vector<T> v;
for (const Vector<T> &e : value)
v.pub(e);
return v;
}
auto begin() { return value.begin(); }
auto end() { return value.end(); }
auto begin() const { return value.begin(); }
auto end() const { return value.end(); }
T sum(int cl = 0, int rl = 0, int cr = -1, int rr = -1) const {
T v = T();
cr = (cr < 0 ? cr + size() + 1 : cr);
for (int i = cl; i < cr; i++)
v += value[i].sum(rl, rr);
return v;
}
T prod(int cl = 0, int rl = 0, int cr = -1, int rr = -1) const {
T v = T() + 1;
cr = (cr < 0 ? cr + size() + 1 : cr);
for (int i = cl; i < cr; i++)
v *= value[i].prod(rl, rr);
return v;
}
T xorsum(int cl = 0, int rl = 0, int cr = -1, int rr = -1) const {
T v = T();
cr = (cr < 0 ? cr + size() + 1 : cr);
for (int i = cl; i < cr; i++)
v ^= value[i].xorsum(rl, rr);
return v;
}
std::pair<int, int> argmin() const {
Vector<int> v(size());
for (int i = 0; i < size(); i++)
v[i] = value[i].min();
int m = v.argmin();
return std::make_pair(m, value[m].argmin());
}
std::pair<int, int> argmax() const {
Vector<int> v(size());
for (int i = 0; i < size(); i++)
v[i] = value[i].max();
int m = v.argmax();
return std::make_pair(m, value[m].argmax());
}
T min() const {
Vector<int> v(size());
for (int i = 0; i < size(); i++)
v[i] = value[i].min();
return v.min();
}
T max() const {
Vector<int> v(size());
for (int i = 0; i < size(); i++)
v[i] = value[i].max();
return v.max();
}
void dot(Matrix<T> v) {
Matrix<T> m(value);
assign(shape().first, v.shape().second, 0);
for (int i = 0; i < shape().first; i++)
for (int j = 0; j < shape().second; j++)
for (int k = 0; k < std::min(m.shape().second, v.shape().first); k++)
value[i][j] += m[i][k] * v[k][j];
}
void resize(int c, Vector<T> v = Vector<T>()) { value.resize(c, v); }
void resize(int c, int r, T v = T()) {
resize(c);
for (Vector<T> &e : value)
e.resize(r, v);
}
void resize(std::pair<int, int> p, T v = T()) {
resize(p.first, p.second, v);
}
void assign(int c, const Vector<T> &v) { value.assign(c, v); }
void assign(int c, int r, T v) { assign(c, Vector<T>(r, v)); }
void assign(std::pair<int, int> p, const T &v) {
assign(p.first, p.second, v);
}
void vstack(const Vector<T> &v) {
if (shape().second < v.size() && size() > 0) {
value.pub(v[{0, shape().second, 1}]);
} else {
value.pub(v);
value.last().resize(shape().second);
}
}
void vstack(const Matrix<T> &v) {
Matrix<T> u(
v[{{0, -1, 1}, {0, std::min(shape().second, v.shape().second), 1}}]);
for (const Vector<T> &e : u)
vstack(e);
}
void hstack(const Vector<T> &v) {
if (size() == 0)
resize(v.size());
for (int i = 0; i < std::min(size(), v.size()); i++)
value[i].pub(v[i]);
resize(shape());
}
void hstack(const Matrix<T> &v) {
if (size() == 0)
resize(v.size());
for (int i = 0; i < std::min(size(), v.size()); i++)
value[i].pub(v[i]);
resize(shape());
}
void vpob() { value.pob(); }
void hpob() {
for (Vector<T> &e : value)
e.pob();
}
void verase(int i, int j = -1) {
if (j == -1)
value.erase(i);
else
value.erase(i, j);
}
void herase(int i, int j = -1) {
for (Vector<T> &e : value)
if (j == -1)
e.erase(i);
else
e.erase(i, j);
}
void vinsert(int i, const Vector<T> &v) {
if (shape() == std::make_pair(int(0), int(0)))
vstack(v);
else
value.insert(i, v[{0, shape().second, 1}]);
}
void vinsert(int i, const Matrix<T> &v) {
if (shape() == std::make_pair(int(0), int(0)))
vstack(v);
else
value.insert(
i, v[{{0, -1, 1}, {0, std::min(shape().second, v.shape().second), 1}}]
.vectorVector());
}
void hinsert(int i, const Vector<T> &v) {
if (shape() == std::make_pair(int(0), int(0)))
hstack(v);
else
for (int j = 0; j < std::min(size(), v.size()); j++)
value[j].insert(i, v[j]);
for (int j = std::min(size(), v.size()); j < size(); j++)
value[j].insert(i, 0);
}
void hinsert(int i, const Matrix<T> &v) {
if (shape() == std::make_pair(int(0), int(0)))
hstack(v);
else
for (int j = 0; j < std::min(size(), v.size()); j++)
value[j].insert(i, v[j]);
for (int j = std::min(size(), v.size()); j < size(); j++)
value[j].resize(v.shape().second);
}
void transpose() {
std::pair<int, int> s = shape();
if (s.first < s.second)
for (int i = 0; i < s.second - s.first; i++)
value.pub(Vector<T>(s.first));
else
for (int i = 0; i < s.second; i++)
value[i].resize(s.first);
for (int i = 0; i < std::min(s.first, s.second); i++)
for (int j = i + 1; j < size(); j++)
std::swap(value[i][j], value[j][i]);
resize(s.second, s.first);
}
void power(int n) {
Matrix<T> m(*this);
assign(size(), size(), 0);
for (int i = 0; i < size(); i++)
value[i][i] = 1;
while (n > 0) {
if (n & 1)
dot(m);
m.dot(m);
n /= 2;
}
}
void cumsum() {
value.cumsum();
for (Vector<T> &e : value)
e.cumsum();
}
void sumdiff() {
value.sumdiff();
for (Vector<T> &e : value)
e.sumdiff();
}
T cumsumpart(int cl, int rl, int cr, int rr) const {
return value[cr - 1][rr - 1] - (cl == 0 ? 0 : value[cl - 1][rr - 1]) -
(rl == 0 ? 0 : value[cr - 1][rl - 1]) +
((cl == 0 || rl == 0) ? 0 : value[cl - 1][rl - 1]);
}
void cumxorsum() {
value.cumxorsum();
for (Vector<T> &e : value)
e.cumxorsum();
}
void xorsumdiff() {
value.xorsumdiff();
for (Vector<T> &e : value)
e.xorsumdiff();
}
T cumxorsumpart(int cl, int rl, int cr, int rr) const {
return value[cr - 1][rr - 1] ^ (cl == 0 ? 0 : value[cl - 1][rr - 1]) ^
(rl == 0 ? 0 : value[cr - 1][rl - 1]) ^
((cl == 0 || rl == 0) ? 0 : value[cl - 1][rl - 1]);
}
void compress() {
Vector<T> u = vector();
u.sortup();
u.erase_unique();
std::unordered_map<T, int> m;
for (int i = 0; i < u.size(); i++)
m[u[i]] = i;
for (int i = 0; i < shape().first; i++)
for (int j = 0; j < shape().second; j++)
value[i][j] = m[value[i][j]];
}
MatCalc(+) MatCalc(-) MatCalc(*) MatCalc(/) MatCalc(%) MatCalc(<<) MatCalc(>>)
MatCalc(&) MatCalc(|) MatCalc(^) MatComp(==) MatComp(!=) MatComp(>=)
MatComp(<=) MatComp(>)
MatComp(<) Matrix<T> vstacked(const Vector<T> &v) const {
Matrix<T> r(*this);
r.vstack(v);
return r;
}
Matrix<T> vstacked(const Matrix<T> &v) const {
Matrix<T> r(*this);
r.vstack(v);
return r;
}
Matrix<T> hstacked(const Vector<T> &v) const {
Matrix<T> r(*this);
r.hstack(v);
return r;
}
Matrix<T> hstacked(const Matrix<T> &v) const {
Matrix<T> r(*this);
r.hstack(v);
return r;
}
Matrix<T> vpobed() const {
Matrix<T> r(*this);
r.vpob();
return r;
}
Matrix<T> hpobed() const {
Matrix<T> r(*this);
r.hpob();
return r;
}
Matrix<T> verased(int i, int j = -1) const {
Matrix<T> r(*this);
r.verase(i, j);
return r;
}
Matrix<T> herased(int i, int j = -1) const {
Matrix<T> r(*this);
r.herase(i, j);
return r;
}
Matrix<T> vinserted(int i, const Vector<T> &v) const {
Matrix<T> r(*this);
r.vinsert(i, v);
return r;
}
Matrix<T> vinserted(int i, const Matrix<T> &v) const {
Matrix<T> r(*this);
r.vinsert(i, v);
return r;
}
Matrix<T> hinserted(int i, const Vector<T> &v) const {
Matrix<T> r(*this);
r.hinsert(i, v);
return r;
}
Matrix<T> hinserted(int i, const Matrix<T> &v) const {
Matrix<T> r(*this);
r.hinsert(i, v);
return r;
}
Matrix<T> transposed() const {
Matrix<T> r(*this);
r.transpose();
return r;
}
Matrix<T> powered(int n) const {
Matrix<T> r(*this);
r.power(n);
return r;
}
Matrix<T> cumsumed() const {
Matrix<T> r(*this);
r.cumsum();
return r;
}
Matrix<T> sumdiffed() const {
Matrix<T> r(*this);
r.sumdiff();
return r;
}
Matrix<T> cumxorsumed() const {
Matrix<T> r(*this);
r.cumxorsum();
return r;
}
Matrix<T> xorsumdiffed() const {
Matrix<T> r(*this);
r.xorsumdiff();
return r;
}
Matrix<T> compressed() const {
Matrix<T> r(*this);
r.compress();
return r;
}
};
// String class need Vector class
#define DefOtherType(RTYPE, OP, CONST) \
RTYPE operator OP(const char *s) CONST { return operator OP(String(s)); } \
RTYPE operator OP(const std::string &s) CONST { \
return operator OP(String(s)); \
} \
RTYPE operator OP(char c) CONST { return operator OP(String(c)); }
#define StrComp(OP) \
bool operator OP(const String &s) const { return str OP s.stdString(); } \
DefOtherType(bool, OP, const)
class String {
std::string str;
public:
String() {}
String(const char *s) : str(s) {}
String(char s) : str(1, s) {}
String(int i, char c) { str = std::string(i, c); }
String(int32_t i) : str(std::to_string(i)) {}
String(int64_t i) : str(std::to_string(i)) {}
String(const std::string &s) : str(s) {}
String(const Vector<char> &v) {
for (char c : v)
pub(c);
}
char operator[](int i) const { return str[i]; }
char &operator[](int i) { return str[i]; }
String operator[](Slice s) const {
s.last = (s.last < 0 ? s.last + size() + 1 : s.last);
String r;
for (int i = s.first; i < s.last; i += s.step)
r.pub(str[i]);
return r;
}
void operator--(int32_t) { pob(); }
String &operator=(const String &s) {
str = s.stdString();
return *this;
}
DefOtherType(String &, =, ) String &operator<<(const String &s) {
pub(s);
return *this;
}
DefOtherType(String &, <<, ) String operator+(const String &s) const {
String r(*this);
r.pub(s);
return r;
}
DefOtherType(String, +, const) String operator+=(const String &s) {
pub(s);
return *this;
}
DefOtherType(String, +=, ) StrComp(==) StrComp(!=) StrComp(>=) StrComp(<=)
StrComp(>) StrComp(<) std::string stdString() const {
return str;
}
std::string &stdString() { return str; }
char last() const { return str[size() - 1]; }
Vector<char> toVector() const {
Vector<char> v;
for (char c : str)
v.pub(c);
return v;
}
char &last() { return str[size() - 1]; }
auto begin() { return str.begin(); }
auto end() { return str.end(); }
auto begin() const { return str.begin(); }
auto end() const { return str.end(); }
int size() const { return str.size(); }
String substr(int p, int s = -1) const {
return operator[]({p, s < 0 ? s : p + s, 1});
}
int32_t toInt() { return std::stoi(str); }
int64_t toLong() { return std::stol(str); }
Vector<int> find(const String &s) const {
Vector<int> v;
auto i = str.find(s.stdString());
while (i != std::string::npos) {
v.pub(i);
i = str.find(s.stdString(), i + s.size());
}
return v;
}
Vector<int> find_dup(const String &s) const {
Vector<int> v;
auto i = str.find(s.stdString());
while (i != std::string::npos) {
v.pub(i);
i = str.find(s.stdString(), i + 1);
}
return v;
}
void resize(int i, char c = 0) { str.resize(i, c); }
void assign(int i, char c) { str.assign(i, c); }
void pub(const String &s) { str += s.stdString(); }
void pob() { str.pop_back(); }
void reverse() { std::reverse(begin(), end()); }
void insert(int i, const String &s) { str.insert(i, s.stdString()); }
void erase(int i, int j = -1) {
if (j < 0)
str.erase(i, 1);
else
str.erase(i, j - i);
}
void erase_unique() { str.erase(std::unique(begin(), end()), end()); }
void rotatedown(int i) { std::rotate(begin(), begin() + i, end()); }
void rotateup(int i) {
std::rotate(str.rbegin(), str.rbegin() + i, str.rend());
}
void sortup() {
int m = *std::min_element(begin(), end());
int M = *std::max_element(begin(), end());
Vector<char> b(M - m + 1);
for (char e : str)
b[e - m]++;
b.cumsum();
for (int i = 0; i < b.size(); i++)
for (int j = (i == 0 ? 0 : b[i - 1]); j < b[i]; j++)
str[j] = m + i;
}
void sortdown() {
sortup();
reverse();
}
String reversed() const {
String r(*this);
r.reverse();
return r;
}
String inserted(int i, const String &s) const {
String r(*this);
r.insert(i, s);
return r;
}
String erased(int i, int j = -1) const {
String r(*this);
r.erase(i, j);
return r;
}
String erase_uniqued() const {
String r(*this);
r.erase_unique();
return r;
}
String rotatedowned(int i) const {
String r(*this);
r.rotatedown(i);
return r;
}
String rotateuped(int i) const {
String r(*this);
r.rotateup(i);
return r;
}
String sortuped() const {
String r(*this);
r.sortup();
return r;
}
String sortdowned() const {
String r(*this);
r.sortdown();
return r;
}
};
std::istream &operator>>(std::istream &i, String &s) {
i >> s.stdString();
return i;
}
std::ostream &operator<<(std::ostream &o, const String &s) {
return o << s.stdString();
}
// Modulo class
#define ModCalc(OP) \
Modulo operator OP(const Modulo &l, const Modulo &r) { \
return Modulo(l.val() OP r.val()); \
} \
Modulo operator OP(const Modulo &l, const int64_t &r) { \
return Modulo(l.val() OP Modulo(r)); \
} \
Modulo operator OP(const int64_t &l, const Modulo &r) { \
return Modulo(l) OP r.val(); \
} \
Modulo operator OP##=(Modulo &l, const Modulo &r) { return l = l OP r; } \
Modulo operator OP##=(Modulo &l, const int64_t &r) { return l = l OP r; } \
int64_t operator OP##=(int64_t &l, const Modulo &r) { \
return l = l OP r.val(); \
}
#define ModComp(OP) \
bool operator OP(const Modulo &l, const Modulo &r) { \
return l.val() OP r.val(); \
} \
bool operator OP(const Modulo &l, const int64_t &r) { return l.val() OP r; } \
bool operator OP(const int64_t &l, const Modulo &r) { return l OP r.val(); }
class Modulo {
int64_t value;
public:
Modulo() : value(0) {}
Modulo(const int64_t &v) {
value = v;
normalize();
}
void normalize() { value = (value % mod() + mod()) % mod(); }
Modulo(const Modulo &m) : value(m.val()) {}
Modulo inv() const {
int64_t a = value;
int64_t b = mod(), u = 0, v = 1;
while (a > 1) {
u -= b / a * v;
b %= a;
std::swap(a, b);
std::swap(u, v);
}
return Modulo(v);
}
int64_t val() const { return value; }
int64_t &val() { return value; }
Modulo &operator=(const Modulo &m) {
value = m.val();
return *this;
}
int64_t mod() const { return MOD; }
Modulo &operator=(const int64_t &v) {
value = v;
return *this;
}
Modulo operator++() { return Modulo(++value); }
Modulo operator--() { return Modulo(--value); }
Modulo operator++(int32_t) { return Modulo(value++); }
Modulo operator--(int32_t) { return Modulo(value--); }
Modulo operator+() const { return *this; }
Modulo operator-() const { return Modulo(-value); }
Modulo power(int64_t i) const {
int64_t x = value;
int64_t r = 1;
while (i > 0) {
if (i & 1)
r = r * x % mod();
x = x * x % mod();
i /= 2;
}
return Modulo(r);
}
};
std::ostream &operator<<(std::ostream &o, const Modulo &m) {
return o << m.val();
}
std::istream &operator>>(std::istream &i, Modulo &m) {
i >> m.val();
m.normalize();
return i;
}
ModCalc(+) ModCalc(-) ModCalc(*) ModCalc(<<) ModCalc(>>) ModCalc(&) ModCalc(|)
ModCalc(^) ModComp(==) ModComp(!=) ModComp(>=) ModComp(<=) ModComp(>)
ModComp(<) Modulo
operator/(const Modulo &l, const Modulo &r) {
return Modulo(l.val() * r.inv());
}
Modulo operator/(const Modulo &l, const int64_t &r) {
return Modulo(l.val() * Modulo(r).inv());
}
Modulo operator/(const int64_t &l, const Modulo &r) {
return Modulo(Modulo(l) * r.inv());
}
// FFT, NNT need Vector Modulo class
std::unordered_map<int, int> MOD_ROOT = {
{1224736769, 3}, {1053818881, 7}, {1051721729, 6}, {1045430273, 3},
{1012924417, 5}, {1007681537, 3}, {1004535809, 3}, {998244353, 3},
{985661441, 3}, {976224257, 3}, {975175681, 17}, {962592769, 7},
{950009857, 7}, {943718401, 7}, {935329793, 3}, {924844033, 5},
{469762049, 3}, {167772161, 3}};
Vector<std::complex<double>> fft(Vector<std::complex<double>> a,
bool inverse = false) {
int n = a.size(), h = std::log2(n);
for (int i = 0; i < n; i++) {
int j = 0;
for (int k = 0; k < h; k++)
j |= (i >> k & 1) << (h - 1 - k);
if (i < j)
std::swap(a[i], a[j]);
}
for (int b = 1; b < n; b *= 2) {
for (int j = 0; j < b; j++) {
std::complex<double> w =
std::polar(1.0, (2 * M_PI) / (2 * b) * j * (inverse ? 1 : -1));
for (int k = 0; k < n; k += b * 2) {
std::complex<double> s = a[j + k], t = a[j + k + b] * w;
a[j + k] = s + t;
a[j + k + b] = s - t;
}
}
}
a /= std::complex<double>(inverse ? n : 1);
return a;
}
Vector<Modulo> ntt(Vector<Modulo> a, bool inverse = false) {
int n = a.size(), h = std::log2(n);
Modulo root = MOD_ROOT[MOD];
for (int i = 0; i < n; i++) {
int j = 0;
for (int k = 0; k < h; k++)
j |= (i >> k & 1) << (h - 1 - k);
if (i < j)
std::swap(a[i], a[j]);
}
for (int b = 1; b < n; b *= 2) {
Modulo w = root.power((a[0].mod() - 1) / (b * 2));
if (inverse)
w = w.inv();
for (int j = 0; j < n; j += b * 2) {
Modulo wn = 1;
for (int k = 0; k < b; k++) {
Modulo s = a[j + k + 0], t = a[j + k + b] * wn;
a[j + k] = s + t;
a[j + k + b] = s - t;
wn = wn * w;
}
}
}
if (inverse) {
Modulo v = Modulo(n).inv();
a *= v;
}
return a;
}
Vector<double> convolve(Vector<double> a, Vector<double> b) {
if (a.size() == 0 || b.size() == 0)
return Vector<double>();
int s = a.size() + b.size() - 1, t = std::pow(2, std::ceil(std::log2(s)));
a.resize(t);
b.resize(t);
Vector<std::complex<double>> A = fft(a), B = fft(b);
A *= B;
A = fft(A, true);
a.resize(s);
for (int i = 0; i < s; i++)
a[i] = A[i].real();
return a;
}
Vector<int> convolve(Vector<int> a, Vector<int> b) {
return convolve(Vector<double>(a), Vector<double>(b)) + 0.5;
}
Vector<Modulo> convolve(Vector<Modulo> a, Vector<Modulo> b) {
if (a.size() == 0 || b.size() == 0)
return Vector<Modulo>();
int s = a.size() + b.size() - 1, t = std::pow(2, std::ceil(std::log2(s)));
a.resize(t);
b.resize(t);
Vector<Modulo> A = ntt(a), B = ntt(b);
A *= B;
a = ntt(A, true);
a.resize(s);
return a;
}
// MultipleVector class need Vector, Modulo class
class MultipleVector {
Vector<Modulo> vfact, ifact, pows;
Modulo p;
public:
MultipleVector(int n = 0, int _p = 1)
: vfact(Vector<Modulo>(1, 1)), ifact(Vector<Modulo>(1, 1)),
pows(Vector<Modulo>(1, 1)), p(_p) {
resize(n);
}
void resize(int n) {
if (vfact.size() >= n)
return;
int s = vfact.size();
vfact.resize(n + 1);
for (int i = s; i <= n; i++)
vfact[i] = i * vfact[i - 1];
ifact.resize(n + 1);
ifact[n] = vfact[n].inv();
for (int i = n; i > s; i--)
ifact[i - 1] = i * ifact[i];
pows.resize(n + 1);
for (int i = s; i <= n; i++)
pows[i] = p * pows[i - 1];
}
Modulo fact(Modulo n) {
resize(n.val());
return vfact[n.val()];
}
Vector<Modulo> facts(Modulo n) {
resize(n.val());
return vfact[{0, n.val(), 1}];
}
Modulo factinv(Modulo n) {
resize(n.val());
return ifact[n.val()];
}
Vector<Modulo> factinvs(Modulo n) {
resize(n.val());
return ifact[{0, n.val(), 1}];
}
Modulo power(Modulo n) {
resize(n.val());
return pows[n.val()];
}
Vector<Modulo> powers(Modulo n) {
resize(n.val());
return pows[{0, n.val(), 1}];
}
Modulo parm(Modulo n, Modulo r) {
if (n < r)
return Modulo();
resize(n.val());
return vfact[n.val()] * ifact[(n - r).val()];
}
Modulo comb(Modulo n, Modulo r) {
if (n < r)
return Modulo();
resize(n.val());
return vfact[n.val()] * ifact[(n - r).val()] * ifact[r.val()];
}
Modulo homo(Modulo n, Modulo r) { return comb(n + r - 1, r); }
};
// Eratos class need Vector class
class Eratos {
Vector<int> divs, prms, ords;
int order_max;
public:
Eratos(int n = 0) : order_max(0) { resize(n); }
int size() const { return divs.size(); }
void resize(int n) {
if (size() >= n)
return;
int m = size();
divs.resize(n + 1);
for (int i = m; i < 2; i++)
if (i < size())
divs[i] = -1;
int r = std::sqrt(n - 1) + 1;
for (int i = 2; i < r; i++)
if (divs[i] == 0)
for (int j = std::max((m - 1) / i + 1, (int)2) * i; j <= n; j += i)
divs[j] = (divs[j] == 0 ? i : divs[j]);
for (int i = m; i <= n; i++)
if (divs[i] == 0)
prms.pub(i);
ords.resize(n + 1);
for (int i = m; i <= n; i++)
ords[i] = (divs[i] == 0 ? ++order_max : 0);
}
Vector<int> divisors() const { return divs; }
Vector<int> primes() const { return prms; }
Vector<int> orders() const { return ords; }
};
// Unionfind class need Vector class
template <typename T> class Unionfind {
Vector<int> p;
Vector<T> w;
int sign(int x) { return (x > 0) - (x < 0); }
int get(int x) {
if (p[x] == (x + 1))
return x + 1;
else {
int parent = sign(p[x]) * get(abs(p[x]) - 1);
w[x] += w[abs(p[x]) - 1];
return p[x] = parent;
}
}
void get(int &x, int &y) {
x = get(x);
y = get(y);
}
int weight(int x) {
get(x);
return w[x];
}
public:
Unionfind(int n = 0) { resize(n); }
void resize(const int &n) {
p.resize(n);
for (int i = w.size(); i < p.size(); i++)
p[i] = i + 1;
w.resize(n);
}
int size() const { return p.size(); }
bool unite(int x, int y, T vv = T()) {
if (vv < 0) {
std::swap(x, y);
vv *= -1;
}
vv += weight(x) - weight(y);
get(x, y);
if (abs(x) == abs(y))
return vv == weight(x) - weight(y);
p[abs(y) - 1] = x * sign(y);
w[abs(y) - 1] = vv;
return true;
}
bool separate(int x, int y, T vv = T()) {
if (vv < 0) {
std::swap(x, y);
vv *= -1;
}
vv += weight(x) - weight(y);
get(x, y);
if (abs(x) == abs(y))
return vv == weight(x) - weight(y);
p[abs(y) - 1] = -x * sign(y);
w[abs(y) - 1] = vv;
return true;
}
int same(int x, int y) {
get(x, y);
return (x == y) - (x == -y);
}
Vector<int> same(int x) {
Vector<int> v(size());
for (int i = 0; i < size(); i++)
v[i] = same(x, i);
return v;
}
T diff(int x, int y) { return sign(same(x, y)) * (weight(y) - weight(x)); }
Vector<T> diff(int x) {
Vector<int> v(size());
for (int i = 0; i < size(); i++)
v[i] = diff(x, i);
return v;
}
};
// Graph class need Vector class
template <typename T> struct Edge {
int from, to;
T cost;
Edge(int f = 0, int t = 0, T c = T()) : from(f), to(t), cost(c) {}
};
template <typename T> std::istream &operator>>(std::istream &i, Edge<T> &e) {
i >> e.from >> e.to >> e.cost;
return i;
}
template <typename T>
std::ostream &operator<<(std::ostream &o, const Edge<T> &e) {
return o << e.from << ' ' << e.to << ' ' << e.cost;
}
template <typename T> class Graph {
public:
Vector<Edge<T>> edge;
Vector<Vector<int>> node;
Graph(int n = 0) { resize(n); }
void resize(int n) { node.resize(n); }
void clear() {
edge = Vector<Edge<T>>();
node = Vector<Vector<int>>(nodes());
}
int edges() const { return edge.size(); }
int nodes() const { return node.size(); }
virtual int add(int from, int to, T cost) = 0;
Vector<T> dijkstra(int start) {
Vector<T> d(nodes(), std::numeric_limits<T>::max());
std::priority_queue<std::pair<T, int>, std::vector<std::pair<T, int>>,
std::greater<std::pair<T, int>>>
s;
d[start] = 0;
s.emplace(d[start], start);
while (!s.empty()) {
T dist = s.top().first;
int from = s.top().second;
s.pop();
if (d[from] < dist)
continue;
for (int id : node[from]) {
int to = edge[id].from ^ edge[id].to ^ from;
if (d[from] + edge[id].cost < d[to]) {
d[to] = d[from] + edge[id].cost;
s.emplace(d[to], to);
}
}
}
return d;
}
};
// Undigraph class need Vector, Graph class
template <typename T> class Undigraph : public Graph<T> {
Vector<int> brgs, crus, lows, ords;
bool lowlinked;
int lowlink_dfs(int from, int k, int parent) {
ords[from] = lows[from] = k++;
bool is_crunode = false;
int cnt = 0;
for (int id : node[from]) {
int to = edge[id].from ^ edge[id].to ^ from;
if (ords[to] == -1) {
cnt++;
k = lowlink_dfs(to, k, from);
lows[from] = std::min(lows[from], lows[to]);
is_crunode |= parent != -1 && lows[to] >= ords[from];
if (ords[from] < lows[to])
brgs.pub(id);
} else if (to != parent)
lows[from] = std::min(lows[from], lows[to]);
}
is_crunode |= parent == -1 && cnt > 1;
if (is_crunode)
crus.pub(from);
return k;
}
void lowlink() {
brgs = Vector<int>();
crus = Vector<int>();
ords.assign(this->nodes(), -1), lows.assign(this->nodes(), -1);
int k = 0;
for (int i = 0; i < this->nodes(); i++)
if (ords[i] == -1)
k = lowlink_dfs(i, k, -1);
lowlinked = true;
}
public:
using Graph<T>::edge;
using Graph<T>::node;
Undigraph(int n = 0) : Graph<T>(n) { lowlinked = false; }
int add(int from, int to, T cost = 1) {
int id = this->edges();
node[from].pub(id);
node[to].pub(id);
edge.pub(Edge<T>(from, to, cost));
return id;
}
void reset_lowlink() { lowlink(); }
Vector<int> bridges() {
if (!lowlinked)
lowlink();
return brgs;
}
Vector<int> crunodes() {
if (!lowlinked)
lowlink();
return crus;
}
T prim(int start = 0) {
Vector<std::pair<T, std::pair<int, int>>> cft;
T total = 0;
Vector<int> used(this->nodes(), 0);
std::priority_queue<std::pair<T, std::pair<int, int>>,
std::vector<std::pair<T, std::pair<int, int>>>,
std::greater<std::pair<T, std::pair<int, int>>>>
s;
s.emplace(std::make_pair(0, std::make_pair(-1, start)));
while (!s.empty()) {
T cost = s.top().first;
int fromfrom = s.top().second.first, from = s.top().second.second;
s.pop();
if (used[from])
continue;
used[from] = true;
total += cost;
if (fromfrom > -1)
cft.pub(std::make_pair(cost, std::make_pair(fromfrom, from)));
for (int id : node[from]) {
int to = edge[id].from ^ edge[id].to ^ from;
s.emplace(std::make_pair(edge[id].cost, std::make_pair(from, to)));
}
}
this->clear();
for (std::pair<T, std::pair<int, int>> e : cft)
add(e.second.first, e.second.second, e.first);
return total;
}
};
// Forest class need Vector, Graph, Undigraph class
template <typename T> class Forest : public Undigraph<T> {
public:
Vector<int> root, parent, treesize, depth;
Vector<T> dist;
Vector<Vector<int>> children;
using Undigraph<T>::edge;
using Undigraph<T>::node;
using Undigraph<T>::resize;
using Undigraph<T>::edges;
using Undigraph<T>::nodes;
Forest(int n = 0) : Undigraph<T>(n) { initialize(); }
void initialize() {
root.assign(nodes(), -1);
parent.assign(nodes(), -1);
treesize.assign(nodes(), 1);
depth.assign(nodes(), 0);
dist.assign(nodes(), 0);
children.assign(nodes(), Vector<int>());
}
private:
void dfs(int from) {
for (int &id : node[from]) {
if (from == edge[id].from)
std::swap(edge[id].from, edge[id].to);
int to = edge[id].from;
if (root[to] != -1)
continue;
root[to] = root[from];
parent[to] = from;
depth[to] = depth[from] + 1;
dist[to] = dist[from] + edge[id].cost;
children[from].pub(to);
dfs(to);
treesize[from] += treesize[to];
}
}
public:
void setTreeRoot(int n) {
initialize();
root[n] = n;
dfs(n);
}
void setForestRoot() {
initialize();
for (int n = 0; n < nodes(); n++)
if (root[n] == -1) {
root[n] = n;
dfs(n);
};
}
T diameter(int n = 0) {
setTreeRoot(n);
int terminal = dist.argmax();
setTreeRoot(terminal);
return dist.max();
}
};
// Digraph class need Vector, Graph class
template <typename T> class Digraph : public Graph<T> {
Vector<Vector<int>> rev_node;
Vector<Edge<T>> rev_edge;
Vector<int> strong_edgeid, weak_edgeid, strong_id, ords;
bool scced;
void scc_dfs(int from) {
if (strong_id[from] == -1)
return;
strong_id[from] = -1;
for (int id : node[from]) {
int to = edge[id].from ^ edge[id].to ^ from;
scc_dfs(to);
}
ords.pub(from);
}
void scc_rdfs(int from, int cnt) {
if (strong_id[from] != -1)
return;
strong_id[from] = cnt;
for (int id : rev_node[from]) {
int to = rev_edge[id].from ^ rev_edge[id].to ^ from;
if (strong_id[to] == -1) {
strong_edgeid.pub(id);
scc_rdfs(to, cnt);
} else if (strong_id[to] == cnt)
strong_edgeid.pub(id);
else if (strong_id[to] < cnt)
weak_edgeid.pub(id);
}
}
public:
using Graph<T>::edge;
using Graph<T>::node;
Digraph(int n = 0) : Graph<T>(n), scced(false) {}
int add(int from, int to, T cost = 1) {
int id = this->edges();
node[from].pub(id);
edge.pub(Edge<T>(from, to, cost));
return id;
}
Digraph<T> reversed() const {
Digraph<T> r(this->edges());
for (Edge<T> e : edge)
r.add(e.to, e.from, e.cost);
return r;
}
void scc() {
strong_edgeid = Vector<int>();
weak_edgeid = Vector<int>();
strong_id.assign(this->nodes(), 0);
ords = Vector<int>(this->nodes());
rev_node = Vector<Vector<int>>(this->nodes());
rev_edge = Vector<Edge<T>>(this->edges());
for (int id = 0; id < this->edges(); id++) {
rev_node[edge[id].to].pub(id);
rev_edge[id] = Edge<T>(edge[id].to, edge[id].from, edge[id].cost);
}
for (int from = 0; from < this->nodes(); from++)
scc_dfs(from);
ords.reverse();
int cnt = 0;
for (int from : ords)
if (strong_id[from] == -1) {
scc_rdfs(from, cnt);
cnt++;
}
Vector<Edge<T>> strong_edge;
for (int id : strong_edgeid)
strong_edge.pub(edge[id]);
this->clear();
for (Edge<T> e : strong_edge)
add(e.from, e.to, e.cost);
scced = true;
}
Vector<int> weakid() {
if (!scced)
scc();
return weak_edgeid;
};
Vector<int> stronggroup() {
if (!scced)
scc();
return strong_id;
}
Vector<T> bellman(int start) {
Vector<T> d(this->nodes(), std::numeric_limits<T>::max());
d[start] = 0;
bool negloop = false;
Vector<int> updating(1, start);
for (int i = 0; i < this->nodes() && updating.size() > 0; i++) {
Vector<int> toUpdate;
for (int from : updating) {
for (int id : node[from]) {
int to = edge[id].from ^ edge[id].to ^ from;
if (d[to] > d[from] + edge[id].cost) {
d[to] = d[from] + edge[id].cost;
toUpdate.pub(to);
if (i == this->nodes() - 1)
d[to] = std::numeric_limits<T>::min();
negloop = true;
}
}
}
updating = toUpdate;
}
if (negloop) {
for (int i = 0; i < this->nodes() && updating.size() > 0; i++) {
Vector<int> toUpdate;
for (int from : updating) {
for (int id : node[from]) {
int to = edge[id].from ^ edge[id].to ^ from;
if (d[to] != std::numeric_limits<T>::min()) {
d[to] = std::numeric_limits<T>::min();
toUpdate.pub(to);
}
}
}
updating = toUpdate;
}
}
return d;
}
Vector<int> topsort() {
Vector<int> to_node(this->nodes(), 0);
for (Edge<T> e : edge)
to_node[e.to]++;
Vector<int> sorted;
for (int i = 0; i < this->nodes(); i++)
if (to_node[i] == 0)
sorted.pub(i);
for (int i = 0; i < sorted.size(); i++)
for (int id : node[sorted[i]]) {
if (--to_node[edge[id].to] == 0)
sorted.pub(edge[id].to);
}
if (sorted.size() != this->nodes())
return Vector<int>();
return sorted;
}
};
// math function for Vector, Matrix, Modulo class
template <typename T> T sign(const T &x) { return (x > 0) - (x < 0); }
template <typename T> T abs(const T &x) { return x * sign(x); }
template <typename T> T power(T x, int y) {
T r = x * 0 + 1;
while (y > 0) {
if (y & 1)
r *= x;
x *= x;
y /= 2;
}
return r;
}
bool is_power(int n, int m) {
return n == power(llround(std::pow(n, (double)+1 / m)), m);
}
int _gcd(const int &a, const int &b) { return b ? _gcd(b, a % b) : a; }
int gcd(const int &a, const int &b) {
return _gcd(std::max(a, b), std::min(a, b));
}
int lcm(const int &a, const int &b) { return a / gcd(a, b) * b; }
bool is_prime(int n) {
int m = std::sqrt(n - 1) + 1;
for (int i = 2; i < m + 1; i++)
if (n % i == 0)
return false;
return n > 1;
}
int fact(int n) {
int v = 1;
for (int i = 1; i < n + 1; i++)
v *= i;
return v;
}
Modulo fact(Modulo n) {
Modulo v = 1;
for (int i = 1; i < n + 1; i++)
v *= i;
return v;
}
int parm(int n, int r) {
int v = 1;
for (int i = n - r + 1; i < n + 1; i++)
v *= i;
return v;
}
Modulo parm(Modulo n, Modulo r) {
Modulo v = 1;
for (int i = n.val() - r.val() + 1; i < n.val() + 1; i++)
v *= i;
return v;
}
int comb(int n, int r) {
int v = 1;
r = std::min(r, n - r);
for (int i = 0; i < r; i++) {
v *= n - i;
v /= i + 1;
}
return v;
}
Modulo comb(Modulo n, Modulo r) {
Modulo p = 1, q = 1;
r = std::min(r, n - r);
for (int i = 0; i < r; i++) {
p *= n - i;
q *= i + 1;
}
return p / q;
}
int homo(int m, int n) { return comb(m + n - 1, n); }
Modulo homo(Modulo m, Modulo n) { return comb(m + n - 1, n); }
// ex. function_find(fname,0,1024,'u',100,output)
#define function_find(FUNCTION_INT_TO_VALUE, INT_RANGE_MIN, INT_RANGE_MAX, \
CHAR_KIND, VALUE_TARGET, INT_AND_OUTPUT) \
{ \
int left = INT_RANGE_MIN - 1; \
int right = INT_RANGE_MAX + 1; \
bool outleft = (CHAR_KIND == 'd' || CHAR_KIND == 'U'); \
int getmin = (CHAR_KIND == 'u' || CHAR_KIND == 'd') ? 1 : -1; \
while (right - left > 1) { \
int mid = left + (right - left) / 2; \
bool OK = FUNCTION_INT_TO_VALUE(mid) * getmin >= VALUE_TARGET * getmin; \
if (outleft == OK) \
left = mid; \
else \
right = mid; \
} \
INT_AND_OUTPUT = outleft ? left : right; \
}
// BinaryIndexedTree class need Vector class
#define BITCalc(OP) \
BinaryIndexedTree<T> operator OP##=(const T &v) { \
if (range.first + 1 == range.second) \
for (int i = range.first; i < size(); i |= (i + 1)) \
t1[i] OP## = v; \
else \
for (int i = range.first; i < size(); i |= (i + 1)) { \
t1[i] OP## = -v * (range.first - 1); \
t2[i] OP## = v; \
} \
for (int i = range.second; i < size(); i |= (i + 1)) { \
t1[i] OP## = v * (range.second - 1); \
t2[i] OP## = -v; \
} \
return *this; \
}
template <typename T> class BinaryIndexedTree {
Vector<T> t1, t2;
std::pair<int, int> range;
public:
T sum(int x) {
T v = T();
for (int i = x; i >= 0; i = (i & (i + 1)) - 1) {
v += t1[i] + t2[i] * x;
}
return v;
}
T sum(int l, int r) { return sum(r - 1) - sum(l - 1); }
T get(int x) { return sum(x, x + 1); }
void resize(int n) {
t1.resize(n);
t2.resize(n);
}
int size() const { return t1.size(); }
Vector<T> firstVector() const { return t1; }
Vector<T> secondVector() const { return t2; }
BinaryIndexedTree(int n = 0) : range(std::make_pair(0, 0)) { resize(n); }
BinaryIndexedTree(const BinaryIndexedTree &bit)
: t1(bit.firstVector()), t2(bit.secondVector()),
range(std::make_pair(0, -1)) {
resize(bit.size());
}
BinaryIndexedTree<T> &operator=(const BinaryIndexedTree<T> &bit) {
resize(bit.size());
t1 = bit.firstVector();
t2 = bit.secondVector();
return *this;
}
T operator[](int i) const { return get(i); }
BinaryIndexedTree<T> &operator[](std::initializer_list<int> l) {
if (l.size() == 1) {
range.first = *l.begin();
range.second = (*l.begin()) + 1;
}
if (l.size() == 2) {
range.first = *l.begin();
range.second = (*(l.begin() + 1) < 0 ? *(l.begin() + 1) + size() + 1
: *(l.begin() + 1));
}
return *this;
}
BITCalc(+) BITCalc(-) T sum() { return sum(range.first, range.second); }
BinaryIndexedTree<T> operator=(const T &v) {
for (int i = range.first; i < range.second; i++) {
operator[]({i});
operator+=(-get(i) + v);
}
return *this;
}
Vector<T> toVector() {
Vector<T> v(size());
for (int i = 0; i < size(); i++)
v[i] = get(i);
return v;
}
};
class Input {
public:
template <typename T> void input_integer(T &var) noexcept {
var = 0;
T sign = 1;
int cc = getchar_unlocked();
for (; cc < '0' || '9' < cc; cc = getchar_unlocked())
if (cc == '-')
sign = -1;
for (; '0' <= cc && cc <= '9'; cc = getchar_unlocked())
var = (var << 3) + (var << 1) + cc - '0';
var = var * sign;
}
Input &operator>>(int32_t &var) {
input_integer(var);
return *this;
}
Input &operator>>(int64_t &var) {
input_integer(var);
return *this;
}
Input &operator>>(std::string &var) {
int c = getchar_unlocked();
while (!(0x21 <= c && c <= 0x7E))
c = getchar_unlocked();
while (0x21 <= c && c <= 0x7E) {
var.push_back(c);
c = getchar_unlocked();
}
return *this;
}
};
Input input;
// BIT^2, graph
// argofsortup
// 10^5 -> NlogN, 3000 -> N^2, 200 -> N^3, 50 -> N^4, 20 -> 2^N
WRITE_FUNCTION_UNDER_HERE
int32_t main() {
INIT;
int n, m;
input >> n >> m;
VPII py(m);
fou(i, 0, py.size()) { input >> py[i].fi >> py[i].se; }
VI order(m);
order.iota();
order = separate((unite(py, order)).sortuped()).se;
py.sortup();
py[0].se = 1;
fou(i, 1, py.size()) {
if (py[i].fi == py[i - 1].fi) {
py[i].se = py[i - 1].se + 1;
} else {
py[i].se = 1;
}
}
py = separate((unite(order, py)).sortuped()).se;
fou(i, 0, py.size()) {
String pref = py[i].fi;
while (pref.size() < 6)
pref.insert(0, '0');
String year = py[i].se;
while (year.size() < 6)
year.insert(0, '0');
out(pref + year);
}
} | replace | 2,132 | 2,133 | 2,132 | 2,134 | TLE | |
p03221 | C++ | Time Limit Exceeded | #pragma GCC optimize( \
"O3,Ofast,inline,fast-math,unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define int int64_t
#define double long double
#define INIT \
std::ios_base::sync_with_stdio(0); \
std::cin.tie(0); \
std::cout << std::fixed << std::setprecision(15);
#define WRITE_FUNCTION_UNDER_HERE DEFALLTYPE(VDEF) DEFALLTYPE(PDEF3)
const int MOD = 1e9 + 7;
using namespace std;
const int MAX = std::numeric_limits<int>::max();
const int MIN = std::numeric_limits<int>::min();
const double EPS = 1e-7;
#define fou(i, a, n) for (int i = a; i < n; i++)
#define fod(i, a, n) for (int i = n - 1; i >= a; i--)
#define tra(e, v) for (auto &e : v)
#define elif(c) else if (c)
#define fi first
#define se second
#define fir fi
#define sec se.fi
#define thi se.se
#define firs fi
#define seco sec
#define thir thi.fi
#define four thi.se
#define DEFALLTYPE(XDEF) \
XDEF(int, I) \
XDEF(double, D) XDEF(char, C) XDEF(String, S) XDEF(bool, B) XDEF(Modulo, M)
#define VDEF(t, T) \
typedef Vector<t> V##T; \
typedef Vector<V##T> VV##T; \
typedef Vector<VV##T> VVV##T;
#define PDEF(x, X, y, Y, z, Z, w, W) \
typedef std::pair<x, y> P##X##Y; \
VDEF(P##X##Y, P##X##Y) typedef std::pair<x, std::pair<y, z>> P##X##Y##Z; \
VDEF(P##X##Y##Z, P##X##Y##Z) \
typedef std::pair<x, std::pair<y, std::pair<z, w>>> P##X##Y##Z##W; \
VDEF(P##X##Y##Z##W, P##X##Y##Z##W)
#define PDEF1(y, Y, z, Z, w, W) \
PDEF(int, I, y, Y, z, Z, w, W) \
PDEF(double, D, y, Y, z, Z, w, W) PDEF(char, C, y, Y, z, Z, w, W) \
PDEF(String, S, y, Y, z, Z, w, W) PDEF(bool, B, y, Y, z, Z, w, W) \
PDEF(Modulo, M, y, Y, z, Z, w, W)
#define PDEF2(z, Z, w, W) \
PDEF1(int, I, z, Z, w, W) \
PDEF1(double, D, z, Z, w, W) PDEF1(char, C, z, Z, w, W) \
PDEF1(String, S, z, Z, w, W) PDEF1(bool, B, z, Z, w, W) \
PDEF1(Modulo, M, z, Z, w, W)
#define PDEF3(w, W) \
PDEF2(int, I, w, W) \
PDEF2(double, D, w, W) PDEF2(char, C, w, W) PDEF2(String, S, w, W) \
PDEF2(bool, B, w, W) PDEF2(Modulo, M, w, W)
// in, out
#define in(T, ...) \
T __VA_ARGS__; \
_in(__VA_ARGS__)
void _in() {}
template <typename Hd, typename... Tl> void _in(Hd &hd, Tl &&...tl) {
std::cin >> hd;
_in(std::forward<Tl>(tl)...);
}
void out() { std::cout << '\n'; }
template <typename T> void out(const T &a) { std::cout << a << '\n'; }
template <typename Hd, typename... Tl> void out(const Hd &hd, const Tl &...tl) {
std::cout << hd << ' ';
out(tl...);
}
// std::pair io,calc
#define PairCalc(OP) \
template <typename T, typename U, typename V, typename W> \
std::pair<T, U> operator OP(const std::pair<T, U> &l, \
const std::pair<V, W> &r) { \
return std::make_pair(l.first OP r.first, l.second OP r.second); \
} \
template <typename T, typename U, typename V, typename W> \
std::pair<T, U> operator OP##=(std::pair<T, U> &l, \
const std::pair<V, W> &r) { \
return l = l OP r; \
}
template <typename T, typename U>
std::istream &operator>>(std::istream &i, std::pair<T, U> &p) {
i >> p.first >> p.second;
return i;
}
template <typename T, typename U>
std::ostream &operator<<(std::ostream &o, const std::pair<T, U> &p) {
return o << p.first << ' ' << p.second;
}
PairCalc(+) PairCalc(-) PairCalc(*) PairCalc(/) PairCalc(%) PairCalc(<<)
PairCalc(>>) PairCalc(&) PairCalc(|)
PairCalc(^) template <typename T, typename U>
std::pair<T, U> mp(const T &t, const U &u) {
return std::make_pair(t, u);
}
template <typename T, typename U, typename V>
std::pair<T, std::pair<U, V>> mp(const T &t, const U &u, const V &v) {
return std::make_pair(t, std::make_pair(u, v));
}
template <typename T, typename U, typename V, typename W>
std::pair<T, std::pair<U, std::pair<V, W>>> mp(const T &t, const U &u,
const V &v, const W &w) {
return std::make_pair(t, std::make_pair(u, std::make_pair(v, w)));
}
// Slice class, Vector class
struct Slice {
int first = 0;
int last = -1;
int step = 1;
Slice(int f, int l = -1, int s = 1) : first(f), last(l), step(s) {}
Slice(std::initializer_list<int> l) {
if (l.size() != 3)
return;
first = *l.begin();
last = *(l.begin() + 1);
step = *(l.begin() + 2);
}
};
#define VecCalc(OP) \
Vector<T> operator OP(const Vector<T> &r) const { \
Vector<T> v(std::min(size(), r.size())); \
for (int i = 0; i < v.size(); i++) \
v[i] = value[i] OP r[i]; \
return v; \
} \
Vector<T> operator OP(const T &r) const { \
Vector<T> v(size()); \
for (int i = 0; i < size(); i++) \
v[i] = value[i] OP r; \
return v; \
} \
Vector<T> operator OP##=(const Vector<T> &r) { return *this = *this OP r; } \
Vector<T> operator OP##=(const T &r) { return *this = *this OP r; }
#define VecComp(OP) \
Vector<int> operator OP(const Vector<T> &r) const { \
Vector<int> v(std::min(size(), r.size())); \
for (int i = 0; i < v.size(); i++) \
v[i] = value[i] OP r[i]; \
return v; \
} \
Vector<int> operator OP(const T &r) const { \
Vector<int> v(size()); \
for (int i = 0; i < size(); i++) \
v[i] = value[i] OP r; \
return v; \
}
#define VVCalc(OP) \
template <typename T, typename U> \
Vector<Vector<T>> operator OP(Vector<Vector<T>> l, const U &r) { \
for (Vector<T> & e : l) \
e OP## = r; \
return l; \
} \
template <typename T, typename U> \
Vector<Vector<T>> operator OP##=(Vector<Vector<T>> &l, const U &r) { \
return l = l OP r; \
}
#define VVComp(OP) \
template <typename T, typename U> \
Vector<Vector<int>> operator OP(const Vector<Vector<T>> &l, const U &r) { \
Vector<Vector<int>> v(l.size()); \
for (int i = 0; i < l.size(); i++) \
v[i] = l[i] OP r; \
return v; \
}
template <typename T> class Vector {
std::vector<T> value;
public:
Vector(int s = 0, T v = T()) {
if (s >= 0)
assign(s, v);
else {
assign(-s, v);
for (T &e : value)
std::cin >> e;
}
}
Vector(const std::initializer_list<T> &l) { value = std::vector<T>{l}; }
template <typename U> Vector(const Vector<U> &v) {
resize(v.size());
for (int i = 0; i < size(); i++)
value[i] = v[i];
}
Vector(const std::vector<T> &v) { value = v; }
int size() const { return value.size(); }
T operator[](int i) const { return value[i]; }
T &operator[](int i) { return value[i]; }
Vector<T> operator[](Slice s) const {
s.last = (s.last < 0 ? s.last + size() + 1 : s.last);
Vector<T> v;
for (int i = s.first; i < s.last; i += s.step)
v.pub(value[i]);
return v;
}
Vector<T> &operator=(const Vector<T> &v) {
resize(v.size());
for (int i = 0; i < size(); i++)
value[i] = v[i];
return *this;
}
Vector<T> operator+() const { return *this; }
Vector<T> operator-() const {
Vector<T> v(value.size());
for (int i = 0; i < size(); i++)
v[i] = -value[i];
return v;
}
Vector<T> operator++() {
for (T &e : value)
e++;
return *this;
}
Vector<T> operator--() {
for (T &e : value)
e--;
return *this;
}
Vector<T> operator++(int32_t) {
Vector<T> v = *this;
for (T &e : value)
e++;
return v;
}
Vector<T> operator--(int32_t) {
Vector<T> v = *this;
for (T &e : value)
e--;
return v;
}
std::vector<T> stdVector() const { return value; }
std::vector<T> &stdVector() { return value; }
void out() {
for (const T &e : value)
std::cout << e << '\n';
}
void iota() {
for (int i = 0; i < size(); i++)
value[i] = i;
}
Vector<T> iotaed() const {
Vector<T> r(*this);
r.iota();
return r;
}
T last() const { return value[size() - 1]; }
T &last() { return value[size() - 1]; }
auto begin() { return value.begin(); }
auto end() { return value.end(); }
auto begin() const { return value.begin(); }
auto end() const { return value.end(); }
T sum(int l = 0, int r = -1) const {
T v = T();
r = (r < 0 ? r + size() + 1 : r);
for (int i = l; i < r; i++)
v += value[i];
return v;
}
T prod(int l = 0, int r = -1) const {
T v = T() + 1;
r = (r < 0 ? r + size() + 1 : r);
for (int i = l; i < r; i++)
v *= value[i];
return v;
}
T xorsum(int l = 0, int r = -1) const {
T v = T();
r = (r < 0 ? r + size() + 1 : r);
for (int i = l; i < r; i++)
v ^= value[i];
return v;
}
int argmin() const { return std::min_element(begin(), end()) - begin(); }
int argmax() const { return std::max_element(begin(), end()) - begin(); }
T min() const { return value[argmin()]; }
T max() const { return value[argmax()]; }
T dot(const Vector<T> &v) const {
T r = T();
for (int i = 0; i < std::min(size(), v.size()); i++)
r += value[i] * v[i];
return r;
}
void resize(int s, T v = T()) { value.resize(s, v); }
void assign(int s, const T &v) { value.assign(s, v); }
void pub(const T &v) { value.push_back(v); }
void pub(const Vector<T> &v) { value.insert(end(), v.begin(), v.end()); }
void insert(int i, const T &v) { value.insert(begin() + i, v); }
void insert(int i, const Vector<T> &v) {
value.insert(begin() + i, v.begin(), v.end());
}
void pob() { value.pop_back(); }
void erase(int i, int j = -1) {
if (j < 0)
value.erase(begin() + i);
else
value.erase(begin() + i, begin() + j);
}
void erase_unique() { value.erase(std::unique(begin(), end()), end()); }
void reverse() { std::reverse(begin(), end()); }
void rotatedown(int i) {
if (i > 0)
std::rotate(begin(), begin() + i, end());
}
void rotateup(int i) {
if (i > 0)
std::rotate(value.rbegin(), value.rbegin() + i, value.rend());
}
void sortup() { std::sort(begin(), end()); }
void sortdown() { std::sort(value.rbegin(), value.rend()); }
void cumsum() {
for (int i = 0; i < size() - 1; i++)
value[i + 1] += value[i];
}
void sumdiff() {
for (int i = size() - 2; i >= 0; i--)
value[i + 1] -= value[i];
}
T cumsumpart(int l, int r) const {
return value[r - 1] - (l = 0 ? 0 : value[l - 1]);
}
void cumxorsum() {
for (int i = 0; i < size() - 1; i++)
value[i + 1] ^= value[i];
}
void xorsumdiff() {
for (int i = size() - 2; i >= 0; i--)
value[i + 1] ^= value[i];
}
T cumxorsumpart(int l, int r) const {
return value[r - 1] ^ (l = 0 ? 0 : value[l - 1]);
}
void bucketsortup() {
int m = min();
Vector<int> b(max() - m + 1);
for (int e : value)
b[e - m]++;
b.cumsum();
for (int i = 0; i < b.size(); i++)
for (int j = (i == 0 ? 0 : b[i - 1]); j < b[i]; j++)
value[j] = m + i;
}
void bucketsortdown() {
bucketsortup();
reverse();
}
void compress() {
Vector<T> u(value);
u.sortup();
u.erase_unique();
std::unordered_map<T, int> m;
for (int i = 0; i < u.size(); i++)
m[u[i]] = i;
for (int i = 0; i < size(); i++)
value[i] = m[value[i]];
}
void argofsortup() {
Vector<std::pair<T, T>> p(size());
for (int i = 0; i < size(); i++)
p[i] = std::make_pair(value[i], i);
p.sortup();
for (int i = 0; i < size(); i++)
value[i] = p[i].second;
}
void argofsortdown() {
Vector<std::pair<T, T>> p(size());
for (int i = 0; i < size(); i++)
p[i] = std::make_pair(value[i], i);
p.sortdown();
for (int i = 0; i < size(); i++)
value[i] = p[i].second;
}
int findupgeq(const T &v) {
return std::lower_bound(begin(), end(), v) - begin();
}
int findupleq(const T &v) {
return std::upper_bound(begin(), end(), v) - begin() - 1;
}
int upcount(const T &v) { return findupleq(v) - findupgeq(v) + 1; }
int finddowngeq(const T &v) {
return size() -
(std::lower_bound(value.rbegin(), value.rend(), v) -
value.rbegin()) -
1;
}
int finddownleq(const T &v) {
return size() -
(std::upper_bound(value.rbegin(), value.rend(), v) - value.rbegin());
}
int downcount(const T &v) { return finddowngeq(v) - finddownleq(v) + 1; }
VecCalc(+) VecCalc(-) VecCalc(*) VecCalc(/) VecCalc(%) VecCalc(<<) VecCalc(>>)
VecCalc(&) VecCalc(|) VecCalc(^) VecComp(==) VecComp(!=) VecComp(>=)
VecComp(<=) VecComp(>) VecComp(<) Vector<T> pubed(const T &v) const {
Vector<T> r(*this);
r.pub(v);
return r;
}
Vector<T> pubed(const Vector<T> &v) const {
Vector<T> r(*this);
r.pub(v);
return r;
}
Vector<T> inserted(int i, const T &v) const {
Vector<T> r(*this);
r.insert(i, v);
return r;
}
Vector<T> inserted(int i, const Vector<T> &v) const {
Vector<T> r(*this);
r.insert(i, v);
return r;
}
Vector<T> pobed() const {
Vector<T> r(*this);
r.pob();
return r;
}
Vector<T> erased(int i, int j = -1) const {
Vector<T> r(*this);
r.erase(i, j);
return r;
}
Vector<T> erase_uniqued() const {
Vector<T> r(*this);
r.erase_unique();
return r;
}
Vector<T> reversed() const {
Vector<T> r(*this);
r.reverse();
return r;
}
Vector<T> rotatedowned(int i) const {
Vector<T> r(*this);
r.rotatedown(i);
return r;
}
Vector<T> rotateuped(int i) const {
Vector<T> r(*this);
r.rotateup(i);
return r;
}
Vector<T> sortuped() const {
Vector<T> r(*this);
r.sortup();
return r;
}
Vector<T> sortdowned() const {
Vector<T> r(*this);
r.sortdown();
return r;
}
Vector<T> cumsumed() const {
Vector<T> r(*this);
r.cumsum();
return r;
}
Vector<T> sumdiffed() const {
Vector<T> r(*this);
r.sumdiff();
return r;
}
Vector<T> cumxorsumed() const {
Vector<T> r(*this);
r.cumxorsum();
return r;
}
Vector<T> xorsumdiffed() const {
Vector<T> r(*this);
r.xorsumdiff();
return r;
}
Vector<T> bucketsortuped() const {
Vector<T> r(*this);
r.bucketsortup();
return r;
}
Vector<T> bucketsortdowned() const {
Vector<T> r(*this);
r.bucketsortdown();
return r;
}
Vector<T> compressed() const {
Vector<T> r(*this);
r.compress();
return r;
}
Vector<T> argofsortuped() const {
Vector<T> r(*this);
r.argofsortup();
return r;
}
Vector<T> argofsortdowned() const {
Vector<T> r(*this);
r.argofsortdown();
return r;
}
};
VVCalc(+) VVCalc(-) VVCalc(*) VVCalc(/) VVCalc(%) VVCalc(<<) VVCalc(>>)
VVCalc(&) VVCalc(|) VVCalc(^) VVComp(==) VVComp(!=) VVComp(>=) VVComp(<=)
VVComp(>) VVComp(<) template <typename T, typename U>
Vector<std::pair<T, U>> unite(const Vector<T> &v, const Vector<U> &u) {
int s = std::min(v.size(), u.size());
Vector<std::pair<T, U>> r(s);
for (int i = 0; i < s; i++)
r[i] = std::make_pair(v[i], u[i]);
return r;
}
template <typename T, typename U>
std::pair<Vector<T>, Vector<U>> separate(const Vector<std::pair<T, U>> &p) {
Vector<T> v(p.size());
Vector<U> u(p.size());
for (int i = 0; i < p.size(); i++) {
v[i] = p[i].first;
u[i] = p[i].second;
}
return std::make_pair(v, u);
}
template <typename T> std::istream &operator>>(std::istream &i, Vector<T> &v) {
for (T &e : v)
i >> e;
return i;
}
template <typename T>
std::ostream &operator<<(std::ostream &o, const Vector<T> &v) {
if (v.size() == 0)
return o;
for (int i = 0; i < v.size() - 1; i++)
o << v[i] << ' ';
return o << v.last();
}
Vector<int> baseVector(int n, int b) {
Vector<int> v(64);
for (int &e : v) {
e = n % b;
n /= b;
}
return v;
}
int baseVectorValue(Vector<int> v, int b) {
int n = 0, m = 1;
for (int &e : v) {
n += e * m;
m *= b;
}
return n;
}
// Matrix class need Vector class
#define MatCalc(OP) \
Matrix<T> operator OP(const Matrix<T> &r) const { \
Matrix<T> v(std::min(size(), r.size())); \
for (int i = 0; i < v.size(); i++) \
v[i] = value[i] OP r[i]; \
return v; \
} \
Matrix<T> operator OP(const Vector<T> &r) const { \
Matrix<T> v(std::min(size(), r.size())); \
for (int i = 0; i < size(); i++) \
v[i] = value[i] OP r; \
return v; \
} \
Matrix<T> operator OP(const T &r) const { \
Matrix<T> v(size()); \
for (int i = 0; i < size(); i++) \
v[i] = value[i] OP r; \
return v; \
} \
Matrix<T> operator OP##=(const Matrix<T> &r) { return *this = *this OP r; } \
Matrix<T> operator OP##=(const Vector<T> &r) { return *this = *this OP r; } \
Matrix<T> operator OP##=(const T &r) { return *this = *this OP r; }
#define MatComp(OP) \
Matrix<int> operator OP(const Matrix<T> &r) const { \
Matrix<int> v(std::min(size(), r.size())); \
for (int i = 0; i < v.size(); i++) \
v[i] = value[i] OP r[i]; \
return v; \
} \
Matrix<int> operator OP(const Vector<T> &r) const { \
Matrix<int> v(size()); \
for (int i = 0; i < size(); i++) \
v[i] = value[i] OP r; \
return v; \
} \
Matrix<int> operator OP(const T &r) const { \
Matrix<int> v(size()); \
for (int i = 0; i < size(); i++) \
v[i] = value[i] OP r; \
return v; \
}
template <typename T> class Matrix {
Vector<Vector<T>> value;
public:
Matrix(int c = 0, int r = 0, T v = T()) {
if (c >= 0 && r >= 0)
assign(c, r, v);
else {
assign(-c, -r, v);
for (Vector<T> &e : value)
std::cin >> e;
}
}
Matrix(std::pair<int, int> p, T v = T()) {
if (p.first >= 0 && p.second >= 0)
assign(p.first, p.second, v);
else {
resize(-p.first, -p.second);
for (Vector<T> &e : value)
std::cin >> e;
}
}
Matrix(const std::initializer_list<std::initializer_list<T>> &l) {
value.resize(l.size());
for (int i = 0; i < size(); i++)
value[i] = *(l.begin() + i);
rect();
}
template <typename U> Matrix(const Matrix<U> &v) {
resize(v.size());
for (int i = 0; i < size(); i++)
value[i] = v[i];
}
Matrix(const Vector<Vector<T>> &v) {
value.resize(v.size());
for (int i = 0; i < size(); i++)
value[i] = v[i];
rect();
}
Matrix(const std::vector<std::vector<T>> &v) {
value.resize(v.size());
for (int i = 0; i < size(); i++)
value[i] = v[i];
rect();
}
void rect() {
Vector<T> v(size());
for (int i = 0; i < size(); i++)
v[i] = value[i].size();
resize(size(), v.max());
}
int size() const { return value.size(); }
std::pair<int, int> shape() const {
return std::make_pair(size(), size() == 0 ? 0 : value[0].size());
}
Vector<T> operator[](int i) const { return value[i]; }
Vector<T> &operator[](int i) { return value[i]; }
T operator[](std::pair<int, int> p) const { return value[p.first][p.second]; }
T &operator[](std::pair<int, int> p) { return value[p.first][p.second]; }
Matrix<T> operator[](Slice p) const { return value[p]; }
Matrix<T> operator[](std::pair<Slice, Slice> p) const {
p.first.last =
(p.first.last < 0 ? p.first.last + shape().first + 1 : p.first.last);
p.second.last = (p.second.last < 0 ? p.second.last + shape().second + 1
: p.second.last);
Matrix<T> v;
for (int i = p.first.first; i < p.first.last; i += p.first.step) {
Vector<T> u;
for (int j = p.second.first; j < p.second.last; j += p.second.step)
u.pub(value[i][j]);
v.vstack(u);
}
return v;
}
Matrix<T> &operator=(const Matrix<T> &v) {
value.resize(size());
for (int i = 0; i < v.size(); i++)
value[i] = v[i];
return *this;
}
Matrix<T> operator+() const { return *this; }
Matrix<T> operator-() const {
Matrix<T> v(value.size());
for (int i = 0; i < size(); i++)
v[i] = -value[i];
return v;
}
Matrix<T> operator++() {
for (Vector<T> &e : value)
e++;
return *this;
}
Matrix<T> operator--() {
for (Vector<T> &e : value)
e--;
return *this;
}
Matrix<T> operator++(int32_t) {
Matrix<T> v = *this;
for (Vector<T> &e : value)
e++;
return v;
}
Matrix<T> operator--(int32_t) {
Matrix<T> v = *this;
for (Vector<T> &e : value)
e--;
return v;
}
std::vector<std::vector<T>> stdVector() {
std::vector<std::vector<T>> v(size());
for (int i = 0; i < size(); i++)
v[i] = value[i].stdVector();
return v;
}
void out() {
for (const Vector<T> &e : value)
std::cout << e << '\n';
}
Vector<Vector<T>> vectorVector() { return value; }
Vector<T> last() const { return value[size() - 1]; }
Vector<T> &last() { return value[size() - 1]; }
Vector<T> vector() const {
Vector<T> v;
for (const Vector<T> &e : value)
v.pub(e);
return v;
}
auto begin() { return value.begin(); }
auto end() { return value.end(); }
auto begin() const { return value.begin(); }
auto end() const { return value.end(); }
T sum(int cl = 0, int rl = 0, int cr = -1, int rr = -1) const {
T v = T();
cr = (cr < 0 ? cr + size() + 1 : cr);
for (int i = cl; i < cr; i++)
v += value[i].sum(rl, rr);
return v;
}
T prod(int cl = 0, int rl = 0, int cr = -1, int rr = -1) const {
T v = T() + 1;
cr = (cr < 0 ? cr + size() + 1 : cr);
for (int i = cl; i < cr; i++)
v *= value[i].prod(rl, rr);
return v;
}
T xorsum(int cl = 0, int rl = 0, int cr = -1, int rr = -1) const {
T v = T();
cr = (cr < 0 ? cr + size() + 1 : cr);
for (int i = cl; i < cr; i++)
v ^= value[i].xorsum(rl, rr);
return v;
}
std::pair<int, int> argmin() const {
Vector<int> v(size());
for (int i = 0; i < size(); i++)
v[i] = value[i].min();
int m = v.argmin();
return std::make_pair(m, value[m].argmin());
}
std::pair<int, int> argmax() const {
Vector<int> v(size());
for (int i = 0; i < size(); i++)
v[i] = value[i].max();
int m = v.argmax();
return std::make_pair(m, value[m].argmax());
}
T min() const {
Vector<int> v(size());
for (int i = 0; i < size(); i++)
v[i] = value[i].min();
return v.min();
}
T max() const {
Vector<int> v(size());
for (int i = 0; i < size(); i++)
v[i] = value[i].max();
return v.max();
}
void dot(Matrix<T> v) {
Matrix<T> m(value);
assign(shape().first, v.shape().second, 0);
for (int i = 0; i < shape().first; i++)
for (int j = 0; j < shape().second; j++)
for (int k = 0; k < std::min(m.shape().second, v.shape().first); k++)
value[i][j] += m[i][k] * v[k][j];
}
void resize(int c, Vector<T> v = Vector<T>()) { value.resize(c, v); }
void resize(int c, int r, T v = T()) {
resize(c);
for (Vector<T> &e : value)
e.resize(r, v);
}
void resize(std::pair<int, int> p, T v = T()) {
resize(p.first, p.second, v);
}
void assign(int c, const Vector<T> &v) { value.assign(c, v); }
void assign(int c, int r, T v) { assign(c, Vector<T>(r, v)); }
void assign(std::pair<int, int> p, const T &v) {
assign(p.first, p.second, v);
}
void vstack(const Vector<T> &v) {
if (shape().second < v.size() && size() > 0) {
value.pub(v[{0, shape().second, 1}]);
} else {
value.pub(v);
value.last().resize(shape().second);
}
}
void vstack(const Matrix<T> &v) {
Matrix<T> u(
v[{{0, -1, 1}, {0, std::min(shape().second, v.shape().second), 1}}]);
for (const Vector<T> &e : u)
vstack(e);
}
void hstack(const Vector<T> &v) {
if (size() == 0)
resize(v.size());
for (int i = 0; i < std::min(size(), v.size()); i++)
value[i].pub(v[i]);
resize(shape());
}
void hstack(const Matrix<T> &v) {
if (size() == 0)
resize(v.size());
for (int i = 0; i < std::min(size(), v.size()); i++)
value[i].pub(v[i]);
resize(shape());
}
void vpob() { value.pob(); }
void hpob() {
for (Vector<T> &e : value)
e.pob();
}
void verase(int i, int j = -1) {
if (j == -1)
value.erase(i);
else
value.erase(i, j);
}
void herase(int i, int j = -1) {
for (Vector<T> &e : value)
if (j == -1)
e.erase(i);
else
e.erase(i, j);
}
void vinsert(int i, const Vector<T> &v) {
if (shape() == std::make_pair(int(0), int(0)))
vstack(v);
else
value.insert(i, v[{0, shape().second, 1}]);
}
void vinsert(int i, const Matrix<T> &v) {
if (shape() == std::make_pair(int(0), int(0)))
vstack(v);
else
value.insert(
i, v[{{0, -1, 1}, {0, std::min(shape().second, v.shape().second), 1}}]
.vectorVector());
}
void hinsert(int i, const Vector<T> &v) {
if (shape() == std::make_pair(int(0), int(0)))
hstack(v);
else
for (int j = 0; j < std::min(size(), v.size()); j++)
value[j].insert(i, v[j]);
for (int j = std::min(size(), v.size()); j < size(); j++)
value[j].insert(i, 0);
}
void hinsert(int i, const Matrix<T> &v) {
if (shape() == std::make_pair(int(0), int(0)))
hstack(v);
else
for (int j = 0; j < std::min(size(), v.size()); j++)
value[j].insert(i, v[j]);
for (int j = std::min(size(), v.size()); j < size(); j++)
value[j].resize(v.shape().second);
}
void transpose() {
std::pair<int, int> s = shape();
if (s.first < s.second)
for (int i = 0; i < s.second - s.first; i++)
value.pub(Vector<T>(s.first));
else
for (int i = 0; i < s.second; i++)
value[i].resize(s.first);
for (int i = 0; i < std::min(s.first, s.second); i++)
for (int j = i + 1; j < size(); j++)
std::swap(value[i][j], value[j][i]);
resize(s.second, s.first);
}
void power(int n) {
Matrix<T> m(*this);
assign(size(), size(), 0);
for (int i = 0; i < size(); i++)
value[i][i] = 1;
while (n > 0) {
if (n & 1)
dot(m);
m.dot(m);
n /= 2;
}
}
void cumsum() {
value.cumsum();
for (Vector<T> &e : value)
e.cumsum();
}
void sumdiff() {
value.sumdiff();
for (Vector<T> &e : value)
e.sumdiff();
}
T cumsumpart(int cl, int rl, int cr, int rr) const {
return value[cr - 1][rr - 1] - (cl == 0 ? 0 : value[cl - 1][rr - 1]) -
(rl == 0 ? 0 : value[cr - 1][rl - 1]) +
((cl == 0 || rl == 0) ? 0 : value[cl - 1][rl - 1]);
}
void cumxorsum() {
value.cumxorsum();
for (Vector<T> &e : value)
e.cumxorsum();
}
void xorsumdiff() {
value.xorsumdiff();
for (Vector<T> &e : value)
e.xorsumdiff();
}
T cumxorsumpart(int cl, int rl, int cr, int rr) const {
return value[cr - 1][rr - 1] ^ (cl == 0 ? 0 : value[cl - 1][rr - 1]) ^
(rl == 0 ? 0 : value[cr - 1][rl - 1]) ^
((cl == 0 || rl == 0) ? 0 : value[cl - 1][rl - 1]);
}
void compress() {
Vector<T> u = vector();
u.sortup();
u.erase_unique();
std::unordered_map<T, int> m;
for (int i = 0; i < u.size(); i++)
m[u[i]] = i;
for (int i = 0; i < shape().first; i++)
for (int j = 0; j < shape().second; j++)
value[i][j] = m[value[i][j]];
}
MatCalc(+) MatCalc(-) MatCalc(*) MatCalc(/) MatCalc(%) MatCalc(<<) MatCalc(>>)
MatCalc(&) MatCalc(|) MatCalc(^) MatComp(==) MatComp(!=) MatComp(>=)
MatComp(<=) MatComp(>)
MatComp(<) Matrix<T> vstacked(const Vector<T> &v) const {
Matrix<T> r(*this);
r.vstack(v);
return r;
}
Matrix<T> vstacked(const Matrix<T> &v) const {
Matrix<T> r(*this);
r.vstack(v);
return r;
}
Matrix<T> hstacked(const Vector<T> &v) const {
Matrix<T> r(*this);
r.hstack(v);
return r;
}
Matrix<T> hstacked(const Matrix<T> &v) const {
Matrix<T> r(*this);
r.hstack(v);
return r;
}
Matrix<T> vpobed() const {
Matrix<T> r(*this);
r.vpob();
return r;
}
Matrix<T> hpobed() const {
Matrix<T> r(*this);
r.hpob();
return r;
}
Matrix<T> verased(int i, int j = -1) const {
Matrix<T> r(*this);
r.verase(i, j);
return r;
}
Matrix<T> herased(int i, int j = -1) const {
Matrix<T> r(*this);
r.herase(i, j);
return r;
}
Matrix<T> vinserted(int i, const Vector<T> &v) const {
Matrix<T> r(*this);
r.vinsert(i, v);
return r;
}
Matrix<T> vinserted(int i, const Matrix<T> &v) const {
Matrix<T> r(*this);
r.vinsert(i, v);
return r;
}
Matrix<T> hinserted(int i, const Vector<T> &v) const {
Matrix<T> r(*this);
r.hinsert(i, v);
return r;
}
Matrix<T> hinserted(int i, const Matrix<T> &v) const {
Matrix<T> r(*this);
r.hinsert(i, v);
return r;
}
Matrix<T> transposed() const {
Matrix<T> r(*this);
r.transpose();
return r;
}
Matrix<T> powered(int n) const {
Matrix<T> r(*this);
r.power(n);
return r;
}
Matrix<T> cumsumed() const {
Matrix<T> r(*this);
r.cumsum();
return r;
}
Matrix<T> sumdiffed() const {
Matrix<T> r(*this);
r.sumdiff();
return r;
}
Matrix<T> cumxorsumed() const {
Matrix<T> r(*this);
r.cumxorsum();
return r;
}
Matrix<T> xorsumdiffed() const {
Matrix<T> r(*this);
r.xorsumdiff();
return r;
}
Matrix<T> compressed() const {
Matrix<T> r(*this);
r.compress();
return r;
}
};
// String class need Vector class
#define DefOtherType(RTYPE, OP, CONST) \
RTYPE operator OP(const char *s) CONST { return operator OP(String(s)); } \
RTYPE operator OP(const std::string &s) CONST { \
return operator OP(String(s)); \
} \
RTYPE operator OP(char c) CONST { return operator OP(String(c)); }
#define StrComp(OP) \
bool operator OP(const String &s) const { return str OP s.stdString(); } \
DefOtherType(bool, OP, const)
class String {
std::string str;
public:
String() {}
String(const char *s) : str(s) {}
String(char s) : str(1, s) {}
String(int i, char c) { str = std::string(i, c); }
String(int32_t i) : str(std::to_string(i)) {}
String(int64_t i) : str(std::to_string(i)) {}
String(const std::string &s) : str(s) {}
String(const Vector<char> &v) {
for (char c : v)
pub(c);
}
char operator[](int i) const { return str[i]; }
char &operator[](int i) { return str[i]; }
String operator[](Slice s) const {
s.last = (s.last < 0 ? s.last + size() + 1 : s.last);
String r;
for (int i = s.first; i < s.last; i += s.step)
r.pub(str[i]);
return r;
}
void operator--(int32_t) { pob(); }
String &operator=(const String &s) {
str = s.stdString();
return *this;
}
DefOtherType(String &, =, ) String &operator<<(const String &s) {
pub(s);
return *this;
}
DefOtherType(String &, <<, ) String operator+(const String &s) const {
String r(*this);
r.pub(s);
return r;
}
DefOtherType(String, +, const) String operator+=(const String &s) {
pub(s);
return *this;
}
DefOtherType(String, +=, ) StrComp(==) StrComp(!=) StrComp(>=) StrComp(<=)
StrComp(>) StrComp(<) std::string stdString() const {
return str;
}
std::string &stdString() { return str; }
char last() const { return str[size() - 1]; }
Vector<char> toVector() const {
Vector<char> v;
for (char c : str)
v.pub(c);
return v;
}
char &last() { return str[size() - 1]; }
auto begin() { return str.begin(); }
auto end() { return str.end(); }
auto begin() const { return str.begin(); }
auto end() const { return str.end(); }
int size() const { return str.size(); }
String substr(int p, int s = -1) const {
return operator[]({p, s < 0 ? s : p + s, 1});
}
int32_t toInt() { return std::stoi(str); }
int64_t toLong() { return std::stol(str); }
Vector<int> find(const String &s) const {
Vector<int> v;
auto i = str.find(s.stdString());
while (i != std::string::npos) {
v.pub(i);
i = str.find(s.stdString(), i + s.size());
}
return v;
}
Vector<int> find_dup(const String &s) const {
Vector<int> v;
auto i = str.find(s.stdString());
while (i != std::string::npos) {
v.pub(i);
i = str.find(s.stdString(), i + 1);
}
return v;
}
void resize(int i, char c = 0) { str.resize(i, c); }
void assign(int i, char c) { str.assign(i, c); }
void pub(const String &s) { str += s.stdString(); }
void pob() { str.pop_back(); }
void reverse() { std::reverse(begin(), end()); }
void insert(int i, const String &s) { str.insert(i, s.stdString()); }
void erase(int i, int j = -1) {
if (j < 0)
str.erase(i, 1);
else
str.erase(i, j - i);
}
void erase_unique() { str.erase(std::unique(begin(), end()), end()); }
void rotatedown(int i) { std::rotate(begin(), begin() + i, end()); }
void rotateup(int i) {
std::rotate(str.rbegin(), str.rbegin() + i, str.rend());
}
void sortup() {
int m = *std::min_element(begin(), end());
int M = *std::max_element(begin(), end());
Vector<char> b(M - m + 1);
for (char e : str)
b[e - m]++;
b.cumsum();
for (int i = 0; i < b.size(); i++)
for (int j = (i == 0 ? 0 : b[i - 1]); j < b[i]; j++)
str[j] = m + i;
}
void sortdown() {
sortup();
reverse();
}
String reversed() const {
String r(*this);
r.reverse();
return r;
}
String inserted(int i, const String &s) const {
String r(*this);
r.insert(i, s);
return r;
}
String erased(int i, int j = -1) const {
String r(*this);
r.erase(i, j);
return r;
}
String erase_uniqued() const {
String r(*this);
r.erase_unique();
return r;
}
String rotatedowned(int i) const {
String r(*this);
r.rotatedown(i);
return r;
}
String rotateuped(int i) const {
String r(*this);
r.rotateup(i);
return r;
}
String sortuped() const {
String r(*this);
r.sortup();
return r;
}
String sortdowned() const {
String r(*this);
r.sortdown();
return r;
}
};
std::istream &operator>>(std::istream &i, String &s) {
i >> s.stdString();
return i;
}
std::ostream &operator<<(std::ostream &o, const String &s) {
return o << s.stdString();
}
// Modulo class
#define ModCalc(OP) \
Modulo operator OP(const Modulo &l, const Modulo &r) { \
return Modulo(l.val() OP r.val()); \
} \
Modulo operator OP(const Modulo &l, const int64_t &r) { \
return Modulo(l.val() OP Modulo(r)); \
} \
Modulo operator OP(const int64_t &l, const Modulo &r) { \
return Modulo(l) OP r.val(); \
} \
Modulo operator OP##=(Modulo &l, const Modulo &r) { return l = l OP r; } \
Modulo operator OP##=(Modulo &l, const int64_t &r) { return l = l OP r; } \
int64_t operator OP##=(int64_t &l, const Modulo &r) { \
return l = l OP r.val(); \
}
#define ModComp(OP) \
bool operator OP(const Modulo &l, const Modulo &r) { \
return l.val() OP r.val(); \
} \
bool operator OP(const Modulo &l, const int64_t &r) { return l.val() OP r; } \
bool operator OP(const int64_t &l, const Modulo &r) { return l OP r.val(); }
class Modulo {
int64_t value;
public:
Modulo() : value(0) {}
Modulo(const int64_t &v) {
value = v;
normalize();
}
void normalize() { value = (value % mod() + mod()) % mod(); }
Modulo(const Modulo &m) : value(m.val()) {}
Modulo inv() const {
int64_t a = value;
int64_t b = mod(), u = 0, v = 1;
while (a > 1) {
u -= b / a * v;
b %= a;
std::swap(a, b);
std::swap(u, v);
}
return Modulo(v);
}
int64_t val() const { return value; }
int64_t &val() { return value; }
Modulo &operator=(const Modulo &m) {
value = m.val();
return *this;
}
int64_t mod() const { return MOD; }
Modulo &operator=(const int64_t &v) {
value = v;
return *this;
}
Modulo operator++() { return Modulo(++value); }
Modulo operator--() { return Modulo(--value); }
Modulo operator++(int32_t) { return Modulo(value++); }
Modulo operator--(int32_t) { return Modulo(value--); }
Modulo operator+() const { return *this; }
Modulo operator-() const { return Modulo(-value); }
Modulo power(int64_t i) const {
int64_t x = value;
int64_t r = 1;
while (i > 0) {
if (i & 1)
r = r * x % mod();
x = x * x % mod();
i /= 2;
}
return Modulo(r);
}
};
std::ostream &operator<<(std::ostream &o, const Modulo &m) {
return o << m.val();
}
std::istream &operator>>(std::istream &i, Modulo &m) {
i >> m.val();
m.normalize();
return i;
}
ModCalc(+) ModCalc(-) ModCalc(*) ModCalc(<<) ModCalc(>>) ModCalc(&) ModCalc(|)
ModCalc(^) ModComp(==) ModComp(!=) ModComp(>=) ModComp(<=) ModComp(>)
ModComp(<) Modulo
operator/(const Modulo &l, const Modulo &r) {
return Modulo(l.val() * r.inv());
}
Modulo operator/(const Modulo &l, const int64_t &r) {
return Modulo(l.val() * Modulo(r).inv());
}
Modulo operator/(const int64_t &l, const Modulo &r) {
return Modulo(Modulo(l) * r.inv());
}
// FFT, NNT need Vector Modulo class
std::unordered_map<int, int> MOD_ROOT = {
{1224736769, 3}, {1053818881, 7}, {1051721729, 6}, {1045430273, 3},
{1012924417, 5}, {1007681537, 3}, {1004535809, 3}, {998244353, 3},
{985661441, 3}, {976224257, 3}, {975175681, 17}, {962592769, 7},
{950009857, 7}, {943718401, 7}, {935329793, 3}, {924844033, 5},
{469762049, 3}, {167772161, 3}};
Vector<std::complex<double>> fft(Vector<std::complex<double>> a,
bool inverse = false) {
int n = a.size(), h = std::log2(n);
for (int i = 0; i < n; i++) {
int j = 0;
for (int k = 0; k < h; k++)
j |= (i >> k & 1) << (h - 1 - k);
if (i < j)
std::swap(a[i], a[j]);
}
for (int b = 1; b < n; b *= 2) {
for (int j = 0; j < b; j++) {
std::complex<double> w =
std::polar(1.0, (2 * M_PI) / (2 * b) * j * (inverse ? 1 : -1));
for (int k = 0; k < n; k += b * 2) {
std::complex<double> s = a[j + k], t = a[j + k + b] * w;
a[j + k] = s + t;
a[j + k + b] = s - t;
}
}
}
a /= std::complex<double>(inverse ? n : 1);
return a;
}
Vector<Modulo> ntt(Vector<Modulo> a, bool inverse = false) {
int n = a.size(), h = std::log2(n);
Modulo root = MOD_ROOT[MOD];
for (int i = 0; i < n; i++) {
int j = 0;
for (int k = 0; k < h; k++)
j |= (i >> k & 1) << (h - 1 - k);
if (i < j)
std::swap(a[i], a[j]);
}
for (int b = 1; b < n; b *= 2) {
Modulo w = root.power((a[0].mod() - 1) / (b * 2));
if (inverse)
w = w.inv();
for (int j = 0; j < n; j += b * 2) {
Modulo wn = 1;
for (int k = 0; k < b; k++) {
Modulo s = a[j + k + 0], t = a[j + k + b] * wn;
a[j + k] = s + t;
a[j + k + b] = s - t;
wn = wn * w;
}
}
}
if (inverse) {
Modulo v = Modulo(n).inv();
a *= v;
}
return a;
}
Vector<double> convolve(Vector<double> a, Vector<double> b) {
if (a.size() == 0 || b.size() == 0)
return Vector<double>();
int s = a.size() + b.size() - 1, t = std::pow(2, std::ceil(std::log2(s)));
a.resize(t);
b.resize(t);
Vector<std::complex<double>> A = fft(a), B = fft(b);
A *= B;
A = fft(A, true);
a.resize(s);
for (int i = 0; i < s; i++)
a[i] = A[i].real();
return a;
}
Vector<int> convolve(Vector<int> a, Vector<int> b) {
return convolve(Vector<double>(a), Vector<double>(b)) + 0.5;
}
Vector<Modulo> convolve(Vector<Modulo> a, Vector<Modulo> b) {
if (a.size() == 0 || b.size() == 0)
return Vector<Modulo>();
int s = a.size() + b.size() - 1, t = std::pow(2, std::ceil(std::log2(s)));
a.resize(t);
b.resize(t);
Vector<Modulo> A = ntt(a), B = ntt(b);
A *= B;
a = ntt(A, true);
a.resize(s);
return a;
}
// MultipleVector class need Vector, Modulo class
class MultipleVector {
Vector<Modulo> vfact, ifact, pows;
Modulo p;
public:
MultipleVector(int n = 0, int _p = 1)
: vfact(Vector<Modulo>(1, 1)), ifact(Vector<Modulo>(1, 1)),
pows(Vector<Modulo>(1, 1)), p(_p) {
resize(n);
}
void resize(int n) {
if (vfact.size() >= n)
return;
int s = vfact.size();
vfact.resize(n + 1);
for (int i = s; i <= n; i++)
vfact[i] = i * vfact[i - 1];
ifact.resize(n + 1);
ifact[n] = vfact[n].inv();
for (int i = n; i > s; i--)
ifact[i - 1] = i * ifact[i];
pows.resize(n + 1);
for (int i = s; i <= n; i++)
pows[i] = p * pows[i - 1];
}
Modulo fact(Modulo n) {
resize(n.val());
return vfact[n.val()];
}
Vector<Modulo> facts(Modulo n) {
resize(n.val());
return vfact[{0, n.val(), 1}];
}
Modulo factinv(Modulo n) {
resize(n.val());
return ifact[n.val()];
}
Vector<Modulo> factinvs(Modulo n) {
resize(n.val());
return ifact[{0, n.val(), 1}];
}
Modulo power(Modulo n) {
resize(n.val());
return pows[n.val()];
}
Vector<Modulo> powers(Modulo n) {
resize(n.val());
return pows[{0, n.val(), 1}];
}
Modulo parm(Modulo n, Modulo r) {
if (n < r)
return Modulo();
resize(n.val());
return vfact[n.val()] * ifact[(n - r).val()];
}
Modulo comb(Modulo n, Modulo r) {
if (n < r)
return Modulo();
resize(n.val());
return vfact[n.val()] * ifact[(n - r).val()] * ifact[r.val()];
}
Modulo homo(Modulo n, Modulo r) { return comb(n + r - 1, r); }
};
// Eratos class need Vector class
class Eratos {
Vector<int> divs, prms, ords;
int order_max;
public:
Eratos(int n = 0) : order_max(0) { resize(n); }
int size() const { return divs.size(); }
void resize(int n) {
if (size() >= n)
return;
int m = size();
divs.resize(n + 1);
for (int i = m; i < 2; i++)
if (i < size())
divs[i] = -1;
int r = std::sqrt(n - 1) + 1;
for (int i = 2; i < r; i++)
if (divs[i] == 0)
for (int j = std::max((m - 1) / i + 1, (int)2) * i; j <= n; j += i)
divs[j] = (divs[j] == 0 ? i : divs[j]);
for (int i = m; i <= n; i++)
if (divs[i] == 0)
prms.pub(i);
ords.resize(n + 1);
for (int i = m; i <= n; i++)
ords[i] = (divs[i] == 0 ? ++order_max : 0);
}
Vector<int> divisors() const { return divs; }
Vector<int> primes() const { return prms; }
Vector<int> orders() const { return ords; }
};
// Unionfind class need Vector class
template <typename T> class Unionfind {
Vector<int> p;
Vector<T> w;
int sign(int x) { return (x > 0) - (x < 0); }
int get(int x) {
if (p[x] == (x + 1))
return x + 1;
else {
int parent = sign(p[x]) * get(abs(p[x]) - 1);
w[x] += w[abs(p[x]) - 1];
return p[x] = parent;
}
}
void get(int &x, int &y) {
x = get(x);
y = get(y);
}
int weight(int x) {
get(x);
return w[x];
}
public:
Unionfind(int n = 0) { resize(n); }
void resize(const int &n) {
p.resize(n);
for (int i = w.size(); i < p.size(); i++)
p[i] = i + 1;
w.resize(n);
}
int size() const { return p.size(); }
bool unite(int x, int y, T vv = T()) {
if (vv < 0) {
std::swap(x, y);
vv *= -1;
}
vv += weight(x) - weight(y);
get(x, y);
if (abs(x) == abs(y))
return vv == weight(x) - weight(y);
p[abs(y) - 1] = x * sign(y);
w[abs(y) - 1] = vv;
return true;
}
bool separate(int x, int y, T vv = T()) {
if (vv < 0) {
std::swap(x, y);
vv *= -1;
}
vv += weight(x) - weight(y);
get(x, y);
if (abs(x) == abs(y))
return vv == weight(x) - weight(y);
p[abs(y) - 1] = -x * sign(y);
w[abs(y) - 1] = vv;
return true;
}
int same(int x, int y) {
get(x, y);
return (x == y) - (x == -y);
}
Vector<int> same(int x) {
Vector<int> v(size());
for (int i = 0; i < size(); i++)
v[i] = same(x, i);
return v;
}
T diff(int x, int y) { return sign(same(x, y)) * (weight(y) - weight(x)); }
Vector<T> diff(int x) {
Vector<int> v(size());
for (int i = 0; i < size(); i++)
v[i] = diff(x, i);
return v;
}
};
// Graph class need Vector class
template <typename T> struct Edge {
int from, to;
T cost;
Edge(int f = 0, int t = 0, T c = T()) : from(f), to(t), cost(c) {}
};
template <typename T> std::istream &operator>>(std::istream &i, Edge<T> &e) {
i >> e.from >> e.to >> e.cost;
return i;
}
template <typename T>
std::ostream &operator<<(std::ostream &o, const Edge<T> &e) {
return o << e.from << ' ' << e.to << ' ' << e.cost;
}
template <typename T> class Graph {
public:
Vector<Edge<T>> edge;
Vector<Vector<int>> node;
Graph(int n = 0) { resize(n); }
void resize(int n) { node.resize(n); }
void clear() {
edge = Vector<Edge<T>>();
node = Vector<Vector<int>>(nodes());
}
int edges() const { return edge.size(); }
int nodes() const { return node.size(); }
virtual int add(int from, int to, T cost) = 0;
Vector<T> dijkstra(int start) {
Vector<T> d(nodes(), std::numeric_limits<T>::max());
std::priority_queue<std::pair<T, int>, std::vector<std::pair<T, int>>,
std::greater<std::pair<T, int>>>
s;
d[start] = 0;
s.emplace(d[start], start);
while (!s.empty()) {
T dist = s.top().first;
int from = s.top().second;
s.pop();
if (d[from] < dist)
continue;
for (int id : node[from]) {
int to = edge[id].from ^ edge[id].to ^ from;
if (d[from] + edge[id].cost < d[to]) {
d[to] = d[from] + edge[id].cost;
s.emplace(d[to], to);
}
}
}
return d;
}
};
// Undigraph class need Vector, Graph class
template <typename T> class Undigraph : public Graph<T> {
Vector<int> brgs, crus, lows, ords;
bool lowlinked;
int lowlink_dfs(int from, int k, int parent) {
ords[from] = lows[from] = k++;
bool is_crunode = false;
int cnt = 0;
for (int id : node[from]) {
int to = edge[id].from ^ edge[id].to ^ from;
if (ords[to] == -1) {
cnt++;
k = lowlink_dfs(to, k, from);
lows[from] = std::min(lows[from], lows[to]);
is_crunode |= parent != -1 && lows[to] >= ords[from];
if (ords[from] < lows[to])
brgs.pub(id);
} else if (to != parent)
lows[from] = std::min(lows[from], lows[to]);
}
is_crunode |= parent == -1 && cnt > 1;
if (is_crunode)
crus.pub(from);
return k;
}
void lowlink() {
brgs = Vector<int>();
crus = Vector<int>();
ords.assign(this->nodes(), -1), lows.assign(this->nodes(), -1);
int k = 0;
for (int i = 0; i < this->nodes(); i++)
if (ords[i] == -1)
k = lowlink_dfs(i, k, -1);
lowlinked = true;
}
public:
using Graph<T>::edge;
using Graph<T>::node;
Undigraph(int n = 0) : Graph<T>(n) { lowlinked = false; }
int add(int from, int to, T cost = 1) {
int id = this->edges();
node[from].pub(id);
node[to].pub(id);
edge.pub(Edge<T>(from, to, cost));
return id;
}
void reset_lowlink() { lowlink(); }
Vector<int> bridges() {
if (!lowlinked)
lowlink();
return brgs;
}
Vector<int> crunodes() {
if (!lowlinked)
lowlink();
return crus;
}
T prim(int start = 0) {
Vector<std::pair<T, std::pair<int, int>>> cft;
T total = 0;
Vector<int> used(this->nodes(), 0);
std::priority_queue<std::pair<T, std::pair<int, int>>,
std::vector<std::pair<T, std::pair<int, int>>>,
std::greater<std::pair<T, std::pair<int, int>>>>
s;
s.emplace(std::make_pair(0, std::make_pair(-1, start)));
while (!s.empty()) {
T cost = s.top().first;
int fromfrom = s.top().second.first, from = s.top().second.second;
s.pop();
if (used[from])
continue;
used[from] = true;
total += cost;
if (fromfrom > -1)
cft.pub(std::make_pair(cost, std::make_pair(fromfrom, from)));
for (int id : node[from]) {
int to = edge[id].from ^ edge[id].to ^ from;
s.emplace(std::make_pair(edge[id].cost, std::make_pair(from, to)));
}
}
this->clear();
for (std::pair<T, std::pair<int, int>> e : cft)
add(e.second.first, e.second.second, e.first);
return total;
}
};
// Forest class need Vector, Graph, Undigraph class
template <typename T> class Forest : public Undigraph<T> {
public:
Vector<int> root, parent, treesize, depth;
Vector<T> dist;
Vector<Vector<int>> children;
using Undigraph<T>::edge;
using Undigraph<T>::node;
using Undigraph<T>::resize;
using Undigraph<T>::edges;
using Undigraph<T>::nodes;
Forest(int n = 0) : Undigraph<T>(n) { initialize(); }
void initialize() {
root.assign(nodes(), -1);
parent.assign(nodes(), -1);
treesize.assign(nodes(), 1);
depth.assign(nodes(), 0);
dist.assign(nodes(), 0);
children.assign(nodes(), Vector<int>());
}
private:
void dfs(int from) {
for (int &id : node[from]) {
if (from == edge[id].from)
std::swap(edge[id].from, edge[id].to);
int to = edge[id].from;
if (root[to] != -1)
continue;
root[to] = root[from];
parent[to] = from;
depth[to] = depth[from] + 1;
dist[to] = dist[from] + edge[id].cost;
children[from].pub(to);
dfs(to);
treesize[from] += treesize[to];
}
}
public:
void setTreeRoot(int n) {
initialize();
root[n] = n;
dfs(n);
}
void setForestRoot() {
initialize();
for (int n = 0; n < nodes(); n++)
if (root[n] == -1) {
root[n] = n;
dfs(n);
};
}
T diameter(int n = 0) {
setTreeRoot(n);
int terminal = dist.argmax();
setTreeRoot(terminal);
return dist.max();
}
};
// Digraph class need Vector, Graph class
template <typename T> class Digraph : public Graph<T> {
Vector<Vector<int>> rev_node;
Vector<Edge<T>> rev_edge;
Vector<int> strong_edgeid, weak_edgeid, strong_id, ords;
bool scced;
void scc_dfs(int from) {
if (strong_id[from] == -1)
return;
strong_id[from] = -1;
for (int id : node[from]) {
int to = edge[id].from ^ edge[id].to ^ from;
scc_dfs(to);
}
ords.pub(from);
}
void scc_rdfs(int from, int cnt) {
if (strong_id[from] != -1)
return;
strong_id[from] = cnt;
for (int id : rev_node[from]) {
int to = rev_edge[id].from ^ rev_edge[id].to ^ from;
if (strong_id[to] == -1) {
strong_edgeid.pub(id);
scc_rdfs(to, cnt);
} else if (strong_id[to] == cnt)
strong_edgeid.pub(id);
else if (strong_id[to] < cnt)
weak_edgeid.pub(id);
}
}
public:
using Graph<T>::edge;
using Graph<T>::node;
Digraph(int n = 0) : Graph<T>(n), scced(false) {}
int add(int from, int to, T cost = 1) {
int id = this->edges();
node[from].pub(id);
edge.pub(Edge<T>(from, to, cost));
return id;
}
Digraph<T> reversed() const {
Digraph<T> r(this->edges());
for (Edge<T> e : edge)
r.add(e.to, e.from, e.cost);
return r;
}
void scc() {
strong_edgeid = Vector<int>();
weak_edgeid = Vector<int>();
strong_id.assign(this->nodes(), 0);
ords = Vector<int>(this->nodes());
rev_node = Vector<Vector<int>>(this->nodes());
rev_edge = Vector<Edge<T>>(this->edges());
for (int id = 0; id < this->edges(); id++) {
rev_node[edge[id].to].pub(id);
rev_edge[id] = Edge<T>(edge[id].to, edge[id].from, edge[id].cost);
}
for (int from = 0; from < this->nodes(); from++)
scc_dfs(from);
ords.reverse();
int cnt = 0;
for (int from : ords)
if (strong_id[from] == -1) {
scc_rdfs(from, cnt);
cnt++;
}
Vector<Edge<T>> strong_edge;
for (int id : strong_edgeid)
strong_edge.pub(edge[id]);
this->clear();
for (Edge<T> e : strong_edge)
add(e.from, e.to, e.cost);
scced = true;
}
Vector<int> weakid() {
if (!scced)
scc();
return weak_edgeid;
};
Vector<int> stronggroup() {
if (!scced)
scc();
return strong_id;
}
Vector<T> bellman(int start) {
Vector<T> d(this->nodes(), std::numeric_limits<T>::max());
d[start] = 0;
bool negloop = false;
Vector<int> updating(1, start);
for (int i = 0; i < this->nodes() && updating.size() > 0; i++) {
Vector<int> toUpdate;
for (int from : updating) {
for (int id : node[from]) {
int to = edge[id].from ^ edge[id].to ^ from;
if (d[to] > d[from] + edge[id].cost) {
d[to] = d[from] + edge[id].cost;
toUpdate.pub(to);
if (i == this->nodes() - 1)
d[to] = std::numeric_limits<T>::min();
negloop = true;
}
}
}
updating = toUpdate;
}
if (negloop) {
for (int i = 0; i < this->nodes() && updating.size() > 0; i++) {
Vector<int> toUpdate;
for (int from : updating) {
for (int id : node[from]) {
int to = edge[id].from ^ edge[id].to ^ from;
if (d[to] != std::numeric_limits<T>::min()) {
d[to] = std::numeric_limits<T>::min();
toUpdate.pub(to);
}
}
}
updating = toUpdate;
}
}
return d;
}
Vector<int> topsort() {
Vector<int> to_node(this->nodes(), 0);
for (Edge<T> e : edge)
to_node[e.to]++;
Vector<int> sorted;
for (int i = 0; i < this->nodes(); i++)
if (to_node[i] == 0)
sorted.pub(i);
for (int i = 0; i < sorted.size(); i++)
for (int id : node[sorted[i]]) {
if (--to_node[edge[id].to] == 0)
sorted.pub(edge[id].to);
}
if (sorted.size() != this->nodes())
return Vector<int>();
return sorted;
}
};
// math function for Vector, Matrix, Modulo class
template <typename T> T sign(const T &x) { return (x > 0) - (x < 0); }
template <typename T> T abs(const T &x) { return x * sign(x); }
template <typename T> T power(T x, int y) {
T r = x * 0 + 1;
while (y > 0) {
if (y & 1)
r *= x;
x *= x;
y /= 2;
}
return r;
}
bool is_power(int n, int m) {
return n == power(llround(std::pow(n, (double)+1 / m)), m);
}
int _gcd(const int &a, const int &b) { return b ? _gcd(b, a % b) : a; }
int gcd(const int &a, const int &b) {
return _gcd(std::max(a, b), std::min(a, b));
}
int lcm(const int &a, const int &b) { return a / gcd(a, b) * b; }
bool is_prime(int n) {
int m = std::sqrt(n - 1) + 1;
for (int i = 2; i < m + 1; i++)
if (n % i == 0)
return false;
return n > 1;
}
int fact(int n) {
int v = 1;
for (int i = 1; i < n + 1; i++)
v *= i;
return v;
}
Modulo fact(Modulo n) {
Modulo v = 1;
for (int i = 1; i < n + 1; i++)
v *= i;
return v;
}
int parm(int n, int r) {
int v = 1;
for (int i = n - r + 1; i < n + 1; i++)
v *= i;
return v;
}
Modulo parm(Modulo n, Modulo r) {
Modulo v = 1;
for (int i = n.val() - r.val() + 1; i < n.val() + 1; i++)
v *= i;
return v;
}
int comb(int n, int r) {
int v = 1;
r = std::min(r, n - r);
for (int i = 0; i < r; i++) {
v *= n - i;
v /= i + 1;
}
return v;
}
Modulo comb(Modulo n, Modulo r) {
Modulo p = 1, q = 1;
r = std::min(r, n - r);
for (int i = 0; i < r; i++) {
p *= n - i;
q *= i + 1;
}
return p / q;
}
int homo(int m, int n) { return comb(m + n - 1, n); }
Modulo homo(Modulo m, Modulo n) { return comb(m + n - 1, n); }
// ex. function_find(fname,0,1024,'u',100,output)
#define function_find(FUNCTION_INT_TO_VALUE, INT_RANGE_MIN, INT_RANGE_MAX, \
CHAR_KIND, VALUE_TARGET, INT_AND_OUTPUT) \
{ \
int left = INT_RANGE_MIN - 1; \
int right = INT_RANGE_MAX + 1; \
bool outleft = (CHAR_KIND == 'd' || CHAR_KIND == 'U'); \
int getmin = (CHAR_KIND == 'u' || CHAR_KIND == 'd') ? 1 : -1; \
while (right - left > 1) { \
int mid = left + (right - left) / 2; \
bool OK = FUNCTION_INT_TO_VALUE(mid) * getmin >= VALUE_TARGET * getmin; \
if (outleft == OK) \
left = mid; \
else \
right = mid; \
} \
INT_AND_OUTPUT = outleft ? left : right; \
}
// BinaryIndexedTree class need Vector class
#define BITCalc(OP) \
BinaryIndexedTree<T> operator OP##=(const T &v) { \
if (range.first + 1 == range.second) \
for (int i = range.first; i < size(); i |= (i + 1)) \
t1[i] OP## = v; \
else \
for (int i = range.first; i < size(); i |= (i + 1)) { \
t1[i] OP## = -v * (range.first - 1); \
t2[i] OP## = v; \
} \
for (int i = range.second; i < size(); i |= (i + 1)) { \
t1[i] OP## = v * (range.second - 1); \
t2[i] OP## = -v; \
} \
return *this; \
}
template <typename T> class BinaryIndexedTree {
Vector<T> t1, t2;
std::pair<int, int> range;
public:
T sum(int x) {
T v = T();
for (int i = x; i >= 0; i = (i & (i + 1)) - 1) {
v += t1[i] + t2[i] * x;
}
return v;
}
T sum(int l, int r) { return sum(r - 1) - sum(l - 1); }
T get(int x) { return sum(x, x + 1); }
void resize(int n) {
t1.resize(n);
t2.resize(n);
}
int size() const { return t1.size(); }
Vector<T> firstVector() const { return t1; }
Vector<T> secondVector() const { return t2; }
BinaryIndexedTree(int n = 0) : range(std::make_pair(0, 0)) { resize(n); }
BinaryIndexedTree(const BinaryIndexedTree &bit)
: t1(bit.firstVector()), t2(bit.secondVector()),
range(std::make_pair(0, -1)) {
resize(bit.size());
}
BinaryIndexedTree<T> &operator=(const BinaryIndexedTree<T> &bit) {
resize(bit.size());
t1 = bit.firstVector();
t2 = bit.secondVector();
return *this;
}
T operator[](int i) const { return get(i); }
BinaryIndexedTree<T> &operator[](std::initializer_list<int> l) {
if (l.size() == 1) {
range.first = *l.begin();
range.second = (*l.begin()) + 1;
}
if (l.size() == 2) {
range.first = *l.begin();
range.second = (*(l.begin() + 1) < 0 ? *(l.begin() + 1) + size() + 1
: *(l.begin() + 1));
}
return *this;
}
BITCalc(+) BITCalc(-) T sum() { return sum(range.first, range.second); }
BinaryIndexedTree<T> operator=(const T &v) {
for (int i = range.first; i < range.second; i++) {
operator[]({i});
operator+=(-get(i) + v);
}
return *this;
}
Vector<T> toVector() {
Vector<T> v(size());
for (int i = 0; i < size(); i++)
v[i] = get(i);
return v;
}
};
class Input {
public:
template <typename T> void input_integer(T &var) {
var = 0;
T sign = 1;
int c = getchar_unlocked();
while (!(('0' <= c && c <= '9') || c == '-'))
c = getchar_unlocked();
if (c == '-') {
sign = -1;
c = getchar_unlocked();
}
while ('0' <= c && c <= '9') {
var = var * 10 + c - '0';
c = getchar_unlocked();
}
var *= sign;
}
Input &operator>>(int32_t &var) {
input_integer<int32_t>(var);
return *this;
}
Input &operator>>(int64_t &var) {
input_integer<int64_t>(var);
return *this;
}
Input &operator>>(std::string &var) {
int c = getchar_unlocked();
while (!(0x21 <= c && c <= 0x7E))
c = getchar_unlocked();
while (0x21 <= c && c <= 0x7E) {
var.push_back(c);
c = getchar_unlocked();
}
return *this;
}
};
Input input;
// BIT^2, graph
// argofsortup
// 10^5 -> NlogN, 3000 -> N^2, 200 -> N^3, 50 -> N^4, 20 -> 2^N
WRITE_FUNCTION_UNDER_HERE
int32_t main() {
INIT;
in(int, n, m);
VPII py(m);
fou(i, 0, py.size()) { input >> py[i].fi >> py[i].se; }
VI order(m);
order.iota();
order = separate((unite(py, order)).sortuped()).se;
py.sortup();
py[0].se = 1;
fou(i, 1, py.size()) {
if (py[i].fi == py[i - 1].fi) {
py[i].se = py[i - 1].se + 1;
} else {
py[i].se = 1;
}
}
py = separate((unite(order, py)).sortuped()).se;
fou(i, 0, py.size()) {
String pref = py[i].fi;
while (pref.size() < 6)
pref.insert(0, '0');
String year = py[i].se;
while (year.size() < 6)
year.insert(0, '0');
out(pref + year);
}
} | #pragma GCC optimize( \
"O3,Ofast,inline,fast-math,unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define int int64_t
#define double long double
#define INIT \
std::ios_base::sync_with_stdio(0); \
std::cin.tie(0); \
std::cout << std::fixed << std::setprecision(15);
#define WRITE_FUNCTION_UNDER_HERE DEFALLTYPE(VDEF) DEFALLTYPE(PDEF3)
const int MOD = 1e9 + 7;
using namespace std;
const int MAX = std::numeric_limits<int>::max();
const int MIN = std::numeric_limits<int>::min();
const double EPS = 1e-7;
#define fou(i, a, n) for (int i = a; i < n; i++)
#define fod(i, a, n) for (int i = n - 1; i >= a; i--)
#define tra(e, v) for (auto &e : v)
#define elif(c) else if (c)
#define fi first
#define se second
#define fir fi
#define sec se.fi
#define thi se.se
#define firs fi
#define seco sec
#define thir thi.fi
#define four thi.se
#define DEFALLTYPE(XDEF) \
XDEF(int, I) \
XDEF(double, D) XDEF(char, C) XDEF(String, S) XDEF(bool, B) XDEF(Modulo, M)
#define VDEF(t, T) \
typedef Vector<t> V##T; \
typedef Vector<V##T> VV##T; \
typedef Vector<VV##T> VVV##T;
#define PDEF(x, X, y, Y, z, Z, w, W) \
typedef std::pair<x, y> P##X##Y; \
VDEF(P##X##Y, P##X##Y) typedef std::pair<x, std::pair<y, z>> P##X##Y##Z; \
VDEF(P##X##Y##Z, P##X##Y##Z) \
typedef std::pair<x, std::pair<y, std::pair<z, w>>> P##X##Y##Z##W; \
VDEF(P##X##Y##Z##W, P##X##Y##Z##W)
#define PDEF1(y, Y, z, Z, w, W) \
PDEF(int, I, y, Y, z, Z, w, W) \
PDEF(double, D, y, Y, z, Z, w, W) PDEF(char, C, y, Y, z, Z, w, W) \
PDEF(String, S, y, Y, z, Z, w, W) PDEF(bool, B, y, Y, z, Z, w, W) \
PDEF(Modulo, M, y, Y, z, Z, w, W)
#define PDEF2(z, Z, w, W) \
PDEF1(int, I, z, Z, w, W) \
PDEF1(double, D, z, Z, w, W) PDEF1(char, C, z, Z, w, W) \
PDEF1(String, S, z, Z, w, W) PDEF1(bool, B, z, Z, w, W) \
PDEF1(Modulo, M, z, Z, w, W)
#define PDEF3(w, W) \
PDEF2(int, I, w, W) \
PDEF2(double, D, w, W) PDEF2(char, C, w, W) PDEF2(String, S, w, W) \
PDEF2(bool, B, w, W) PDEF2(Modulo, M, w, W)
// in, out
#define in(T, ...) \
T __VA_ARGS__; \
_in(__VA_ARGS__)
void _in() {}
template <typename Hd, typename... Tl> void _in(Hd &hd, Tl &&...tl) {
std::cin >> hd;
_in(std::forward<Tl>(tl)...);
}
void out() { std::cout << '\n'; }
template <typename T> void out(const T &a) { std::cout << a << '\n'; }
template <typename Hd, typename... Tl> void out(const Hd &hd, const Tl &...tl) {
std::cout << hd << ' ';
out(tl...);
}
// std::pair io,calc
#define PairCalc(OP) \
template <typename T, typename U, typename V, typename W> \
std::pair<T, U> operator OP(const std::pair<T, U> &l, \
const std::pair<V, W> &r) { \
return std::make_pair(l.first OP r.first, l.second OP r.second); \
} \
template <typename T, typename U, typename V, typename W> \
std::pair<T, U> operator OP##=(std::pair<T, U> &l, \
const std::pair<V, W> &r) { \
return l = l OP r; \
}
template <typename T, typename U>
std::istream &operator>>(std::istream &i, std::pair<T, U> &p) {
i >> p.first >> p.second;
return i;
}
template <typename T, typename U>
std::ostream &operator<<(std::ostream &o, const std::pair<T, U> &p) {
return o << p.first << ' ' << p.second;
}
PairCalc(+) PairCalc(-) PairCalc(*) PairCalc(/) PairCalc(%) PairCalc(<<)
PairCalc(>>) PairCalc(&) PairCalc(|)
PairCalc(^) template <typename T, typename U>
std::pair<T, U> mp(const T &t, const U &u) {
return std::make_pair(t, u);
}
template <typename T, typename U, typename V>
std::pair<T, std::pair<U, V>> mp(const T &t, const U &u, const V &v) {
return std::make_pair(t, std::make_pair(u, v));
}
template <typename T, typename U, typename V, typename W>
std::pair<T, std::pair<U, std::pair<V, W>>> mp(const T &t, const U &u,
const V &v, const W &w) {
return std::make_pair(t, std::make_pair(u, std::make_pair(v, w)));
}
// Slice class, Vector class
struct Slice {
int first = 0;
int last = -1;
int step = 1;
Slice(int f, int l = -1, int s = 1) : first(f), last(l), step(s) {}
Slice(std::initializer_list<int> l) {
if (l.size() != 3)
return;
first = *l.begin();
last = *(l.begin() + 1);
step = *(l.begin() + 2);
}
};
#define VecCalc(OP) \
Vector<T> operator OP(const Vector<T> &r) const { \
Vector<T> v(std::min(size(), r.size())); \
for (int i = 0; i < v.size(); i++) \
v[i] = value[i] OP r[i]; \
return v; \
} \
Vector<T> operator OP(const T &r) const { \
Vector<T> v(size()); \
for (int i = 0; i < size(); i++) \
v[i] = value[i] OP r; \
return v; \
} \
Vector<T> operator OP##=(const Vector<T> &r) { return *this = *this OP r; } \
Vector<T> operator OP##=(const T &r) { return *this = *this OP r; }
#define VecComp(OP) \
Vector<int> operator OP(const Vector<T> &r) const { \
Vector<int> v(std::min(size(), r.size())); \
for (int i = 0; i < v.size(); i++) \
v[i] = value[i] OP r[i]; \
return v; \
} \
Vector<int> operator OP(const T &r) const { \
Vector<int> v(size()); \
for (int i = 0; i < size(); i++) \
v[i] = value[i] OP r; \
return v; \
}
#define VVCalc(OP) \
template <typename T, typename U> \
Vector<Vector<T>> operator OP(Vector<Vector<T>> l, const U &r) { \
for (Vector<T> & e : l) \
e OP## = r; \
return l; \
} \
template <typename T, typename U> \
Vector<Vector<T>> operator OP##=(Vector<Vector<T>> &l, const U &r) { \
return l = l OP r; \
}
#define VVComp(OP) \
template <typename T, typename U> \
Vector<Vector<int>> operator OP(const Vector<Vector<T>> &l, const U &r) { \
Vector<Vector<int>> v(l.size()); \
for (int i = 0; i < l.size(); i++) \
v[i] = l[i] OP r; \
return v; \
}
template <typename T> class Vector {
std::vector<T> value;
public:
Vector(int s = 0, T v = T()) {
if (s >= 0)
assign(s, v);
else {
assign(-s, v);
for (T &e : value)
std::cin >> e;
}
}
Vector(const std::initializer_list<T> &l) { value = std::vector<T>{l}; }
template <typename U> Vector(const Vector<U> &v) {
resize(v.size());
for (int i = 0; i < size(); i++)
value[i] = v[i];
}
Vector(const std::vector<T> &v) { value = v; }
int size() const { return value.size(); }
T operator[](int i) const { return value[i]; }
T &operator[](int i) { return value[i]; }
Vector<T> operator[](Slice s) const {
s.last = (s.last < 0 ? s.last + size() + 1 : s.last);
Vector<T> v;
for (int i = s.first; i < s.last; i += s.step)
v.pub(value[i]);
return v;
}
Vector<T> &operator=(const Vector<T> &v) {
resize(v.size());
for (int i = 0; i < size(); i++)
value[i] = v[i];
return *this;
}
Vector<T> operator+() const { return *this; }
Vector<T> operator-() const {
Vector<T> v(value.size());
for (int i = 0; i < size(); i++)
v[i] = -value[i];
return v;
}
Vector<T> operator++() {
for (T &e : value)
e++;
return *this;
}
Vector<T> operator--() {
for (T &e : value)
e--;
return *this;
}
Vector<T> operator++(int32_t) {
Vector<T> v = *this;
for (T &e : value)
e++;
return v;
}
Vector<T> operator--(int32_t) {
Vector<T> v = *this;
for (T &e : value)
e--;
return v;
}
std::vector<T> stdVector() const { return value; }
std::vector<T> &stdVector() { return value; }
void out() {
for (const T &e : value)
std::cout << e << '\n';
}
void iota() {
for (int i = 0; i < size(); i++)
value[i] = i;
}
Vector<T> iotaed() const {
Vector<T> r(*this);
r.iota();
return r;
}
T last() const { return value[size() - 1]; }
T &last() { return value[size() - 1]; }
auto begin() { return value.begin(); }
auto end() { return value.end(); }
auto begin() const { return value.begin(); }
auto end() const { return value.end(); }
T sum(int l = 0, int r = -1) const {
T v = T();
r = (r < 0 ? r + size() + 1 : r);
for (int i = l; i < r; i++)
v += value[i];
return v;
}
T prod(int l = 0, int r = -1) const {
T v = T() + 1;
r = (r < 0 ? r + size() + 1 : r);
for (int i = l; i < r; i++)
v *= value[i];
return v;
}
T xorsum(int l = 0, int r = -1) const {
T v = T();
r = (r < 0 ? r + size() + 1 : r);
for (int i = l; i < r; i++)
v ^= value[i];
return v;
}
int argmin() const { return std::min_element(begin(), end()) - begin(); }
int argmax() const { return std::max_element(begin(), end()) - begin(); }
T min() const { return value[argmin()]; }
T max() const { return value[argmax()]; }
T dot(const Vector<T> &v) const {
T r = T();
for (int i = 0; i < std::min(size(), v.size()); i++)
r += value[i] * v[i];
return r;
}
void resize(int s, T v = T()) { value.resize(s, v); }
void assign(int s, const T &v) { value.assign(s, v); }
void pub(const T &v) { value.push_back(v); }
void pub(const Vector<T> &v) { value.insert(end(), v.begin(), v.end()); }
void insert(int i, const T &v) { value.insert(begin() + i, v); }
void insert(int i, const Vector<T> &v) {
value.insert(begin() + i, v.begin(), v.end());
}
void pob() { value.pop_back(); }
void erase(int i, int j = -1) {
if (j < 0)
value.erase(begin() + i);
else
value.erase(begin() + i, begin() + j);
}
void erase_unique() { value.erase(std::unique(begin(), end()), end()); }
void reverse() { std::reverse(begin(), end()); }
void rotatedown(int i) {
if (i > 0)
std::rotate(begin(), begin() + i, end());
}
void rotateup(int i) {
if (i > 0)
std::rotate(value.rbegin(), value.rbegin() + i, value.rend());
}
void sortup() { std::sort(begin(), end()); }
void sortdown() { std::sort(value.rbegin(), value.rend()); }
void cumsum() {
for (int i = 0; i < size() - 1; i++)
value[i + 1] += value[i];
}
void sumdiff() {
for (int i = size() - 2; i >= 0; i--)
value[i + 1] -= value[i];
}
T cumsumpart(int l, int r) const {
return value[r - 1] - (l = 0 ? 0 : value[l - 1]);
}
void cumxorsum() {
for (int i = 0; i < size() - 1; i++)
value[i + 1] ^= value[i];
}
void xorsumdiff() {
for (int i = size() - 2; i >= 0; i--)
value[i + 1] ^= value[i];
}
T cumxorsumpart(int l, int r) const {
return value[r - 1] ^ (l = 0 ? 0 : value[l - 1]);
}
void bucketsortup() {
int m = min();
Vector<int> b(max() - m + 1);
for (int e : value)
b[e - m]++;
b.cumsum();
for (int i = 0; i < b.size(); i++)
for (int j = (i == 0 ? 0 : b[i - 1]); j < b[i]; j++)
value[j] = m + i;
}
void bucketsortdown() {
bucketsortup();
reverse();
}
void compress() {
Vector<T> u(value);
u.sortup();
u.erase_unique();
std::unordered_map<T, int> m;
for (int i = 0; i < u.size(); i++)
m[u[i]] = i;
for (int i = 0; i < size(); i++)
value[i] = m[value[i]];
}
void argofsortup() {
Vector<std::pair<T, T>> p(size());
for (int i = 0; i < size(); i++)
p[i] = std::make_pair(value[i], i);
p.sortup();
for (int i = 0; i < size(); i++)
value[i] = p[i].second;
}
void argofsortdown() {
Vector<std::pair<T, T>> p(size());
for (int i = 0; i < size(); i++)
p[i] = std::make_pair(value[i], i);
p.sortdown();
for (int i = 0; i < size(); i++)
value[i] = p[i].second;
}
int findupgeq(const T &v) {
return std::lower_bound(begin(), end(), v) - begin();
}
int findupleq(const T &v) {
return std::upper_bound(begin(), end(), v) - begin() - 1;
}
int upcount(const T &v) { return findupleq(v) - findupgeq(v) + 1; }
int finddowngeq(const T &v) {
return size() -
(std::lower_bound(value.rbegin(), value.rend(), v) -
value.rbegin()) -
1;
}
int finddownleq(const T &v) {
return size() -
(std::upper_bound(value.rbegin(), value.rend(), v) - value.rbegin());
}
int downcount(const T &v) { return finddowngeq(v) - finddownleq(v) + 1; }
VecCalc(+) VecCalc(-) VecCalc(*) VecCalc(/) VecCalc(%) VecCalc(<<) VecCalc(>>)
VecCalc(&) VecCalc(|) VecCalc(^) VecComp(==) VecComp(!=) VecComp(>=)
VecComp(<=) VecComp(>) VecComp(<) Vector<T> pubed(const T &v) const {
Vector<T> r(*this);
r.pub(v);
return r;
}
Vector<T> pubed(const Vector<T> &v) const {
Vector<T> r(*this);
r.pub(v);
return r;
}
Vector<T> inserted(int i, const T &v) const {
Vector<T> r(*this);
r.insert(i, v);
return r;
}
Vector<T> inserted(int i, const Vector<T> &v) const {
Vector<T> r(*this);
r.insert(i, v);
return r;
}
Vector<T> pobed() const {
Vector<T> r(*this);
r.pob();
return r;
}
Vector<T> erased(int i, int j = -1) const {
Vector<T> r(*this);
r.erase(i, j);
return r;
}
Vector<T> erase_uniqued() const {
Vector<T> r(*this);
r.erase_unique();
return r;
}
Vector<T> reversed() const {
Vector<T> r(*this);
r.reverse();
return r;
}
Vector<T> rotatedowned(int i) const {
Vector<T> r(*this);
r.rotatedown(i);
return r;
}
Vector<T> rotateuped(int i) const {
Vector<T> r(*this);
r.rotateup(i);
return r;
}
Vector<T> sortuped() const {
Vector<T> r(*this);
r.sortup();
return r;
}
Vector<T> sortdowned() const {
Vector<T> r(*this);
r.sortdown();
return r;
}
Vector<T> cumsumed() const {
Vector<T> r(*this);
r.cumsum();
return r;
}
Vector<T> sumdiffed() const {
Vector<T> r(*this);
r.sumdiff();
return r;
}
Vector<T> cumxorsumed() const {
Vector<T> r(*this);
r.cumxorsum();
return r;
}
Vector<T> xorsumdiffed() const {
Vector<T> r(*this);
r.xorsumdiff();
return r;
}
Vector<T> bucketsortuped() const {
Vector<T> r(*this);
r.bucketsortup();
return r;
}
Vector<T> bucketsortdowned() const {
Vector<T> r(*this);
r.bucketsortdown();
return r;
}
Vector<T> compressed() const {
Vector<T> r(*this);
r.compress();
return r;
}
Vector<T> argofsortuped() const {
Vector<T> r(*this);
r.argofsortup();
return r;
}
Vector<T> argofsortdowned() const {
Vector<T> r(*this);
r.argofsortdown();
return r;
}
};
VVCalc(+) VVCalc(-) VVCalc(*) VVCalc(/) VVCalc(%) VVCalc(<<) VVCalc(>>)
VVCalc(&) VVCalc(|) VVCalc(^) VVComp(==) VVComp(!=) VVComp(>=) VVComp(<=)
VVComp(>) VVComp(<) template <typename T, typename U>
Vector<std::pair<T, U>> unite(const Vector<T> &v, const Vector<U> &u) {
int s = std::min(v.size(), u.size());
Vector<std::pair<T, U>> r(s);
for (int i = 0; i < s; i++)
r[i] = std::make_pair(v[i], u[i]);
return r;
}
template <typename T, typename U>
std::pair<Vector<T>, Vector<U>> separate(const Vector<std::pair<T, U>> &p) {
Vector<T> v(p.size());
Vector<U> u(p.size());
for (int i = 0; i < p.size(); i++) {
v[i] = p[i].first;
u[i] = p[i].second;
}
return std::make_pair(v, u);
}
template <typename T> std::istream &operator>>(std::istream &i, Vector<T> &v) {
for (T &e : v)
i >> e;
return i;
}
template <typename T>
std::ostream &operator<<(std::ostream &o, const Vector<T> &v) {
if (v.size() == 0)
return o;
for (int i = 0; i < v.size() - 1; i++)
o << v[i] << ' ';
return o << v.last();
}
Vector<int> baseVector(int n, int b) {
Vector<int> v(64);
for (int &e : v) {
e = n % b;
n /= b;
}
return v;
}
int baseVectorValue(Vector<int> v, int b) {
int n = 0, m = 1;
for (int &e : v) {
n += e * m;
m *= b;
}
return n;
}
// Matrix class need Vector class
#define MatCalc(OP) \
Matrix<T> operator OP(const Matrix<T> &r) const { \
Matrix<T> v(std::min(size(), r.size())); \
for (int i = 0; i < v.size(); i++) \
v[i] = value[i] OP r[i]; \
return v; \
} \
Matrix<T> operator OP(const Vector<T> &r) const { \
Matrix<T> v(std::min(size(), r.size())); \
for (int i = 0; i < size(); i++) \
v[i] = value[i] OP r; \
return v; \
} \
Matrix<T> operator OP(const T &r) const { \
Matrix<T> v(size()); \
for (int i = 0; i < size(); i++) \
v[i] = value[i] OP r; \
return v; \
} \
Matrix<T> operator OP##=(const Matrix<T> &r) { return *this = *this OP r; } \
Matrix<T> operator OP##=(const Vector<T> &r) { return *this = *this OP r; } \
Matrix<T> operator OP##=(const T &r) { return *this = *this OP r; }
#define MatComp(OP) \
Matrix<int> operator OP(const Matrix<T> &r) const { \
Matrix<int> v(std::min(size(), r.size())); \
for (int i = 0; i < v.size(); i++) \
v[i] = value[i] OP r[i]; \
return v; \
} \
Matrix<int> operator OP(const Vector<T> &r) const { \
Matrix<int> v(size()); \
for (int i = 0; i < size(); i++) \
v[i] = value[i] OP r; \
return v; \
} \
Matrix<int> operator OP(const T &r) const { \
Matrix<int> v(size()); \
for (int i = 0; i < size(); i++) \
v[i] = value[i] OP r; \
return v; \
}
template <typename T> class Matrix {
Vector<Vector<T>> value;
public:
Matrix(int c = 0, int r = 0, T v = T()) {
if (c >= 0 && r >= 0)
assign(c, r, v);
else {
assign(-c, -r, v);
for (Vector<T> &e : value)
std::cin >> e;
}
}
Matrix(std::pair<int, int> p, T v = T()) {
if (p.first >= 0 && p.second >= 0)
assign(p.first, p.second, v);
else {
resize(-p.first, -p.second);
for (Vector<T> &e : value)
std::cin >> e;
}
}
Matrix(const std::initializer_list<std::initializer_list<T>> &l) {
value.resize(l.size());
for (int i = 0; i < size(); i++)
value[i] = *(l.begin() + i);
rect();
}
template <typename U> Matrix(const Matrix<U> &v) {
resize(v.size());
for (int i = 0; i < size(); i++)
value[i] = v[i];
}
Matrix(const Vector<Vector<T>> &v) {
value.resize(v.size());
for (int i = 0; i < size(); i++)
value[i] = v[i];
rect();
}
Matrix(const std::vector<std::vector<T>> &v) {
value.resize(v.size());
for (int i = 0; i < size(); i++)
value[i] = v[i];
rect();
}
void rect() {
Vector<T> v(size());
for (int i = 0; i < size(); i++)
v[i] = value[i].size();
resize(size(), v.max());
}
int size() const { return value.size(); }
std::pair<int, int> shape() const {
return std::make_pair(size(), size() == 0 ? 0 : value[0].size());
}
Vector<T> operator[](int i) const { return value[i]; }
Vector<T> &operator[](int i) { return value[i]; }
T operator[](std::pair<int, int> p) const { return value[p.first][p.second]; }
T &operator[](std::pair<int, int> p) { return value[p.first][p.second]; }
Matrix<T> operator[](Slice p) const { return value[p]; }
Matrix<T> operator[](std::pair<Slice, Slice> p) const {
p.first.last =
(p.first.last < 0 ? p.first.last + shape().first + 1 : p.first.last);
p.second.last = (p.second.last < 0 ? p.second.last + shape().second + 1
: p.second.last);
Matrix<T> v;
for (int i = p.first.first; i < p.first.last; i += p.first.step) {
Vector<T> u;
for (int j = p.second.first; j < p.second.last; j += p.second.step)
u.pub(value[i][j]);
v.vstack(u);
}
return v;
}
Matrix<T> &operator=(const Matrix<T> &v) {
value.resize(size());
for (int i = 0; i < v.size(); i++)
value[i] = v[i];
return *this;
}
Matrix<T> operator+() const { return *this; }
Matrix<T> operator-() const {
Matrix<T> v(value.size());
for (int i = 0; i < size(); i++)
v[i] = -value[i];
return v;
}
Matrix<T> operator++() {
for (Vector<T> &e : value)
e++;
return *this;
}
Matrix<T> operator--() {
for (Vector<T> &e : value)
e--;
return *this;
}
Matrix<T> operator++(int32_t) {
Matrix<T> v = *this;
for (Vector<T> &e : value)
e++;
return v;
}
Matrix<T> operator--(int32_t) {
Matrix<T> v = *this;
for (Vector<T> &e : value)
e--;
return v;
}
std::vector<std::vector<T>> stdVector() {
std::vector<std::vector<T>> v(size());
for (int i = 0; i < size(); i++)
v[i] = value[i].stdVector();
return v;
}
void out() {
for (const Vector<T> &e : value)
std::cout << e << '\n';
}
Vector<Vector<T>> vectorVector() { return value; }
Vector<T> last() const { return value[size() - 1]; }
Vector<T> &last() { return value[size() - 1]; }
Vector<T> vector() const {
Vector<T> v;
for (const Vector<T> &e : value)
v.pub(e);
return v;
}
auto begin() { return value.begin(); }
auto end() { return value.end(); }
auto begin() const { return value.begin(); }
auto end() const { return value.end(); }
T sum(int cl = 0, int rl = 0, int cr = -1, int rr = -1) const {
T v = T();
cr = (cr < 0 ? cr + size() + 1 : cr);
for (int i = cl; i < cr; i++)
v += value[i].sum(rl, rr);
return v;
}
T prod(int cl = 0, int rl = 0, int cr = -1, int rr = -1) const {
T v = T() + 1;
cr = (cr < 0 ? cr + size() + 1 : cr);
for (int i = cl; i < cr; i++)
v *= value[i].prod(rl, rr);
return v;
}
T xorsum(int cl = 0, int rl = 0, int cr = -1, int rr = -1) const {
T v = T();
cr = (cr < 0 ? cr + size() + 1 : cr);
for (int i = cl; i < cr; i++)
v ^= value[i].xorsum(rl, rr);
return v;
}
std::pair<int, int> argmin() const {
Vector<int> v(size());
for (int i = 0; i < size(); i++)
v[i] = value[i].min();
int m = v.argmin();
return std::make_pair(m, value[m].argmin());
}
std::pair<int, int> argmax() const {
Vector<int> v(size());
for (int i = 0; i < size(); i++)
v[i] = value[i].max();
int m = v.argmax();
return std::make_pair(m, value[m].argmax());
}
T min() const {
Vector<int> v(size());
for (int i = 0; i < size(); i++)
v[i] = value[i].min();
return v.min();
}
T max() const {
Vector<int> v(size());
for (int i = 0; i < size(); i++)
v[i] = value[i].max();
return v.max();
}
void dot(Matrix<T> v) {
Matrix<T> m(value);
assign(shape().first, v.shape().second, 0);
for (int i = 0; i < shape().first; i++)
for (int j = 0; j < shape().second; j++)
for (int k = 0; k < std::min(m.shape().second, v.shape().first); k++)
value[i][j] += m[i][k] * v[k][j];
}
void resize(int c, Vector<T> v = Vector<T>()) { value.resize(c, v); }
void resize(int c, int r, T v = T()) {
resize(c);
for (Vector<T> &e : value)
e.resize(r, v);
}
void resize(std::pair<int, int> p, T v = T()) {
resize(p.first, p.second, v);
}
void assign(int c, const Vector<T> &v) { value.assign(c, v); }
void assign(int c, int r, T v) { assign(c, Vector<T>(r, v)); }
void assign(std::pair<int, int> p, const T &v) {
assign(p.first, p.second, v);
}
void vstack(const Vector<T> &v) {
if (shape().second < v.size() && size() > 0) {
value.pub(v[{0, shape().second, 1}]);
} else {
value.pub(v);
value.last().resize(shape().second);
}
}
void vstack(const Matrix<T> &v) {
Matrix<T> u(
v[{{0, -1, 1}, {0, std::min(shape().second, v.shape().second), 1}}]);
for (const Vector<T> &e : u)
vstack(e);
}
void hstack(const Vector<T> &v) {
if (size() == 0)
resize(v.size());
for (int i = 0; i < std::min(size(), v.size()); i++)
value[i].pub(v[i]);
resize(shape());
}
void hstack(const Matrix<T> &v) {
if (size() == 0)
resize(v.size());
for (int i = 0; i < std::min(size(), v.size()); i++)
value[i].pub(v[i]);
resize(shape());
}
void vpob() { value.pob(); }
void hpob() {
for (Vector<T> &e : value)
e.pob();
}
void verase(int i, int j = -1) {
if (j == -1)
value.erase(i);
else
value.erase(i, j);
}
void herase(int i, int j = -1) {
for (Vector<T> &e : value)
if (j == -1)
e.erase(i);
else
e.erase(i, j);
}
void vinsert(int i, const Vector<T> &v) {
if (shape() == std::make_pair(int(0), int(0)))
vstack(v);
else
value.insert(i, v[{0, shape().second, 1}]);
}
void vinsert(int i, const Matrix<T> &v) {
if (shape() == std::make_pair(int(0), int(0)))
vstack(v);
else
value.insert(
i, v[{{0, -1, 1}, {0, std::min(shape().second, v.shape().second), 1}}]
.vectorVector());
}
void hinsert(int i, const Vector<T> &v) {
if (shape() == std::make_pair(int(0), int(0)))
hstack(v);
else
for (int j = 0; j < std::min(size(), v.size()); j++)
value[j].insert(i, v[j]);
for (int j = std::min(size(), v.size()); j < size(); j++)
value[j].insert(i, 0);
}
void hinsert(int i, const Matrix<T> &v) {
if (shape() == std::make_pair(int(0), int(0)))
hstack(v);
else
for (int j = 0; j < std::min(size(), v.size()); j++)
value[j].insert(i, v[j]);
for (int j = std::min(size(), v.size()); j < size(); j++)
value[j].resize(v.shape().second);
}
void transpose() {
std::pair<int, int> s = shape();
if (s.first < s.second)
for (int i = 0; i < s.second - s.first; i++)
value.pub(Vector<T>(s.first));
else
for (int i = 0; i < s.second; i++)
value[i].resize(s.first);
for (int i = 0; i < std::min(s.first, s.second); i++)
for (int j = i + 1; j < size(); j++)
std::swap(value[i][j], value[j][i]);
resize(s.second, s.first);
}
void power(int n) {
Matrix<T> m(*this);
assign(size(), size(), 0);
for (int i = 0; i < size(); i++)
value[i][i] = 1;
while (n > 0) {
if (n & 1)
dot(m);
m.dot(m);
n /= 2;
}
}
void cumsum() {
value.cumsum();
for (Vector<T> &e : value)
e.cumsum();
}
void sumdiff() {
value.sumdiff();
for (Vector<T> &e : value)
e.sumdiff();
}
T cumsumpart(int cl, int rl, int cr, int rr) const {
return value[cr - 1][rr - 1] - (cl == 0 ? 0 : value[cl - 1][rr - 1]) -
(rl == 0 ? 0 : value[cr - 1][rl - 1]) +
((cl == 0 || rl == 0) ? 0 : value[cl - 1][rl - 1]);
}
void cumxorsum() {
value.cumxorsum();
for (Vector<T> &e : value)
e.cumxorsum();
}
void xorsumdiff() {
value.xorsumdiff();
for (Vector<T> &e : value)
e.xorsumdiff();
}
T cumxorsumpart(int cl, int rl, int cr, int rr) const {
return value[cr - 1][rr - 1] ^ (cl == 0 ? 0 : value[cl - 1][rr - 1]) ^
(rl == 0 ? 0 : value[cr - 1][rl - 1]) ^
((cl == 0 || rl == 0) ? 0 : value[cl - 1][rl - 1]);
}
void compress() {
Vector<T> u = vector();
u.sortup();
u.erase_unique();
std::unordered_map<T, int> m;
for (int i = 0; i < u.size(); i++)
m[u[i]] = i;
for (int i = 0; i < shape().first; i++)
for (int j = 0; j < shape().second; j++)
value[i][j] = m[value[i][j]];
}
MatCalc(+) MatCalc(-) MatCalc(*) MatCalc(/) MatCalc(%) MatCalc(<<) MatCalc(>>)
MatCalc(&) MatCalc(|) MatCalc(^) MatComp(==) MatComp(!=) MatComp(>=)
MatComp(<=) MatComp(>)
MatComp(<) Matrix<T> vstacked(const Vector<T> &v) const {
Matrix<T> r(*this);
r.vstack(v);
return r;
}
Matrix<T> vstacked(const Matrix<T> &v) const {
Matrix<T> r(*this);
r.vstack(v);
return r;
}
Matrix<T> hstacked(const Vector<T> &v) const {
Matrix<T> r(*this);
r.hstack(v);
return r;
}
Matrix<T> hstacked(const Matrix<T> &v) const {
Matrix<T> r(*this);
r.hstack(v);
return r;
}
Matrix<T> vpobed() const {
Matrix<T> r(*this);
r.vpob();
return r;
}
Matrix<T> hpobed() const {
Matrix<T> r(*this);
r.hpob();
return r;
}
Matrix<T> verased(int i, int j = -1) const {
Matrix<T> r(*this);
r.verase(i, j);
return r;
}
Matrix<T> herased(int i, int j = -1) const {
Matrix<T> r(*this);
r.herase(i, j);
return r;
}
Matrix<T> vinserted(int i, const Vector<T> &v) const {
Matrix<T> r(*this);
r.vinsert(i, v);
return r;
}
Matrix<T> vinserted(int i, const Matrix<T> &v) const {
Matrix<T> r(*this);
r.vinsert(i, v);
return r;
}
Matrix<T> hinserted(int i, const Vector<T> &v) const {
Matrix<T> r(*this);
r.hinsert(i, v);
return r;
}
Matrix<T> hinserted(int i, const Matrix<T> &v) const {
Matrix<T> r(*this);
r.hinsert(i, v);
return r;
}
Matrix<T> transposed() const {
Matrix<T> r(*this);
r.transpose();
return r;
}
Matrix<T> powered(int n) const {
Matrix<T> r(*this);
r.power(n);
return r;
}
Matrix<T> cumsumed() const {
Matrix<T> r(*this);
r.cumsum();
return r;
}
Matrix<T> sumdiffed() const {
Matrix<T> r(*this);
r.sumdiff();
return r;
}
Matrix<T> cumxorsumed() const {
Matrix<T> r(*this);
r.cumxorsum();
return r;
}
Matrix<T> xorsumdiffed() const {
Matrix<T> r(*this);
r.xorsumdiff();
return r;
}
Matrix<T> compressed() const {
Matrix<T> r(*this);
r.compress();
return r;
}
};
// String class need Vector class
#define DefOtherType(RTYPE, OP, CONST) \
RTYPE operator OP(const char *s) CONST { return operator OP(String(s)); } \
RTYPE operator OP(const std::string &s) CONST { \
return operator OP(String(s)); \
} \
RTYPE operator OP(char c) CONST { return operator OP(String(c)); }
#define StrComp(OP) \
bool operator OP(const String &s) const { return str OP s.stdString(); } \
DefOtherType(bool, OP, const)
class String {
std::string str;
public:
String() {}
String(const char *s) : str(s) {}
String(char s) : str(1, s) {}
String(int i, char c) { str = std::string(i, c); }
String(int32_t i) : str(std::to_string(i)) {}
String(int64_t i) : str(std::to_string(i)) {}
String(const std::string &s) : str(s) {}
String(const Vector<char> &v) {
for (char c : v)
pub(c);
}
char operator[](int i) const { return str[i]; }
char &operator[](int i) { return str[i]; }
String operator[](Slice s) const {
s.last = (s.last < 0 ? s.last + size() + 1 : s.last);
String r;
for (int i = s.first; i < s.last; i += s.step)
r.pub(str[i]);
return r;
}
void operator--(int32_t) { pob(); }
String &operator=(const String &s) {
str = s.stdString();
return *this;
}
DefOtherType(String &, =, ) String &operator<<(const String &s) {
pub(s);
return *this;
}
DefOtherType(String &, <<, ) String operator+(const String &s) const {
String r(*this);
r.pub(s);
return r;
}
DefOtherType(String, +, const) String operator+=(const String &s) {
pub(s);
return *this;
}
DefOtherType(String, +=, ) StrComp(==) StrComp(!=) StrComp(>=) StrComp(<=)
StrComp(>) StrComp(<) std::string stdString() const {
return str;
}
std::string &stdString() { return str; }
char last() const { return str[size() - 1]; }
Vector<char> toVector() const {
Vector<char> v;
for (char c : str)
v.pub(c);
return v;
}
char &last() { return str[size() - 1]; }
auto begin() { return str.begin(); }
auto end() { return str.end(); }
auto begin() const { return str.begin(); }
auto end() const { return str.end(); }
int size() const { return str.size(); }
String substr(int p, int s = -1) const {
return operator[]({p, s < 0 ? s : p + s, 1});
}
int32_t toInt() { return std::stoi(str); }
int64_t toLong() { return std::stol(str); }
Vector<int> find(const String &s) const {
Vector<int> v;
auto i = str.find(s.stdString());
while (i != std::string::npos) {
v.pub(i);
i = str.find(s.stdString(), i + s.size());
}
return v;
}
Vector<int> find_dup(const String &s) const {
Vector<int> v;
auto i = str.find(s.stdString());
while (i != std::string::npos) {
v.pub(i);
i = str.find(s.stdString(), i + 1);
}
return v;
}
void resize(int i, char c = 0) { str.resize(i, c); }
void assign(int i, char c) { str.assign(i, c); }
void pub(const String &s) { str += s.stdString(); }
void pob() { str.pop_back(); }
void reverse() { std::reverse(begin(), end()); }
void insert(int i, const String &s) { str.insert(i, s.stdString()); }
void erase(int i, int j = -1) {
if (j < 0)
str.erase(i, 1);
else
str.erase(i, j - i);
}
void erase_unique() { str.erase(std::unique(begin(), end()), end()); }
void rotatedown(int i) { std::rotate(begin(), begin() + i, end()); }
void rotateup(int i) {
std::rotate(str.rbegin(), str.rbegin() + i, str.rend());
}
void sortup() {
int m = *std::min_element(begin(), end());
int M = *std::max_element(begin(), end());
Vector<char> b(M - m + 1);
for (char e : str)
b[e - m]++;
b.cumsum();
for (int i = 0; i < b.size(); i++)
for (int j = (i == 0 ? 0 : b[i - 1]); j < b[i]; j++)
str[j] = m + i;
}
void sortdown() {
sortup();
reverse();
}
String reversed() const {
String r(*this);
r.reverse();
return r;
}
String inserted(int i, const String &s) const {
String r(*this);
r.insert(i, s);
return r;
}
String erased(int i, int j = -1) const {
String r(*this);
r.erase(i, j);
return r;
}
String erase_uniqued() const {
String r(*this);
r.erase_unique();
return r;
}
String rotatedowned(int i) const {
String r(*this);
r.rotatedown(i);
return r;
}
String rotateuped(int i) const {
String r(*this);
r.rotateup(i);
return r;
}
String sortuped() const {
String r(*this);
r.sortup();
return r;
}
String sortdowned() const {
String r(*this);
r.sortdown();
return r;
}
};
std::istream &operator>>(std::istream &i, String &s) {
i >> s.stdString();
return i;
}
std::ostream &operator<<(std::ostream &o, const String &s) {
return o << s.stdString();
}
// Modulo class
#define ModCalc(OP) \
Modulo operator OP(const Modulo &l, const Modulo &r) { \
return Modulo(l.val() OP r.val()); \
} \
Modulo operator OP(const Modulo &l, const int64_t &r) { \
return Modulo(l.val() OP Modulo(r)); \
} \
Modulo operator OP(const int64_t &l, const Modulo &r) { \
return Modulo(l) OP r.val(); \
} \
Modulo operator OP##=(Modulo &l, const Modulo &r) { return l = l OP r; } \
Modulo operator OP##=(Modulo &l, const int64_t &r) { return l = l OP r; } \
int64_t operator OP##=(int64_t &l, const Modulo &r) { \
return l = l OP r.val(); \
}
#define ModComp(OP) \
bool operator OP(const Modulo &l, const Modulo &r) { \
return l.val() OP r.val(); \
} \
bool operator OP(const Modulo &l, const int64_t &r) { return l.val() OP r; } \
bool operator OP(const int64_t &l, const Modulo &r) { return l OP r.val(); }
class Modulo {
int64_t value;
public:
Modulo() : value(0) {}
Modulo(const int64_t &v) {
value = v;
normalize();
}
void normalize() { value = (value % mod() + mod()) % mod(); }
Modulo(const Modulo &m) : value(m.val()) {}
Modulo inv() const {
int64_t a = value;
int64_t b = mod(), u = 0, v = 1;
while (a > 1) {
u -= b / a * v;
b %= a;
std::swap(a, b);
std::swap(u, v);
}
return Modulo(v);
}
int64_t val() const { return value; }
int64_t &val() { return value; }
Modulo &operator=(const Modulo &m) {
value = m.val();
return *this;
}
int64_t mod() const { return MOD; }
Modulo &operator=(const int64_t &v) {
value = v;
return *this;
}
Modulo operator++() { return Modulo(++value); }
Modulo operator--() { return Modulo(--value); }
Modulo operator++(int32_t) { return Modulo(value++); }
Modulo operator--(int32_t) { return Modulo(value--); }
Modulo operator+() const { return *this; }
Modulo operator-() const { return Modulo(-value); }
Modulo power(int64_t i) const {
int64_t x = value;
int64_t r = 1;
while (i > 0) {
if (i & 1)
r = r * x % mod();
x = x * x % mod();
i /= 2;
}
return Modulo(r);
}
};
std::ostream &operator<<(std::ostream &o, const Modulo &m) {
return o << m.val();
}
std::istream &operator>>(std::istream &i, Modulo &m) {
i >> m.val();
m.normalize();
return i;
}
ModCalc(+) ModCalc(-) ModCalc(*) ModCalc(<<) ModCalc(>>) ModCalc(&) ModCalc(|)
ModCalc(^) ModComp(==) ModComp(!=) ModComp(>=) ModComp(<=) ModComp(>)
ModComp(<) Modulo
operator/(const Modulo &l, const Modulo &r) {
return Modulo(l.val() * r.inv());
}
Modulo operator/(const Modulo &l, const int64_t &r) {
return Modulo(l.val() * Modulo(r).inv());
}
Modulo operator/(const int64_t &l, const Modulo &r) {
return Modulo(Modulo(l) * r.inv());
}
// FFT, NNT need Vector Modulo class
std::unordered_map<int, int> MOD_ROOT = {
{1224736769, 3}, {1053818881, 7}, {1051721729, 6}, {1045430273, 3},
{1012924417, 5}, {1007681537, 3}, {1004535809, 3}, {998244353, 3},
{985661441, 3}, {976224257, 3}, {975175681, 17}, {962592769, 7},
{950009857, 7}, {943718401, 7}, {935329793, 3}, {924844033, 5},
{469762049, 3}, {167772161, 3}};
Vector<std::complex<double>> fft(Vector<std::complex<double>> a,
bool inverse = false) {
int n = a.size(), h = std::log2(n);
for (int i = 0; i < n; i++) {
int j = 0;
for (int k = 0; k < h; k++)
j |= (i >> k & 1) << (h - 1 - k);
if (i < j)
std::swap(a[i], a[j]);
}
for (int b = 1; b < n; b *= 2) {
for (int j = 0; j < b; j++) {
std::complex<double> w =
std::polar(1.0, (2 * M_PI) / (2 * b) * j * (inverse ? 1 : -1));
for (int k = 0; k < n; k += b * 2) {
std::complex<double> s = a[j + k], t = a[j + k + b] * w;
a[j + k] = s + t;
a[j + k + b] = s - t;
}
}
}
a /= std::complex<double>(inverse ? n : 1);
return a;
}
Vector<Modulo> ntt(Vector<Modulo> a, bool inverse = false) {
int n = a.size(), h = std::log2(n);
Modulo root = MOD_ROOT[MOD];
for (int i = 0; i < n; i++) {
int j = 0;
for (int k = 0; k < h; k++)
j |= (i >> k & 1) << (h - 1 - k);
if (i < j)
std::swap(a[i], a[j]);
}
for (int b = 1; b < n; b *= 2) {
Modulo w = root.power((a[0].mod() - 1) / (b * 2));
if (inverse)
w = w.inv();
for (int j = 0; j < n; j += b * 2) {
Modulo wn = 1;
for (int k = 0; k < b; k++) {
Modulo s = a[j + k + 0], t = a[j + k + b] * wn;
a[j + k] = s + t;
a[j + k + b] = s - t;
wn = wn * w;
}
}
}
if (inverse) {
Modulo v = Modulo(n).inv();
a *= v;
}
return a;
}
Vector<double> convolve(Vector<double> a, Vector<double> b) {
if (a.size() == 0 || b.size() == 0)
return Vector<double>();
int s = a.size() + b.size() - 1, t = std::pow(2, std::ceil(std::log2(s)));
a.resize(t);
b.resize(t);
Vector<std::complex<double>> A = fft(a), B = fft(b);
A *= B;
A = fft(A, true);
a.resize(s);
for (int i = 0; i < s; i++)
a[i] = A[i].real();
return a;
}
Vector<int> convolve(Vector<int> a, Vector<int> b) {
return convolve(Vector<double>(a), Vector<double>(b)) + 0.5;
}
Vector<Modulo> convolve(Vector<Modulo> a, Vector<Modulo> b) {
if (a.size() == 0 || b.size() == 0)
return Vector<Modulo>();
int s = a.size() + b.size() - 1, t = std::pow(2, std::ceil(std::log2(s)));
a.resize(t);
b.resize(t);
Vector<Modulo> A = ntt(a), B = ntt(b);
A *= B;
a = ntt(A, true);
a.resize(s);
return a;
}
// MultipleVector class need Vector, Modulo class
class MultipleVector {
Vector<Modulo> vfact, ifact, pows;
Modulo p;
public:
MultipleVector(int n = 0, int _p = 1)
: vfact(Vector<Modulo>(1, 1)), ifact(Vector<Modulo>(1, 1)),
pows(Vector<Modulo>(1, 1)), p(_p) {
resize(n);
}
void resize(int n) {
if (vfact.size() >= n)
return;
int s = vfact.size();
vfact.resize(n + 1);
for (int i = s; i <= n; i++)
vfact[i] = i * vfact[i - 1];
ifact.resize(n + 1);
ifact[n] = vfact[n].inv();
for (int i = n; i > s; i--)
ifact[i - 1] = i * ifact[i];
pows.resize(n + 1);
for (int i = s; i <= n; i++)
pows[i] = p * pows[i - 1];
}
Modulo fact(Modulo n) {
resize(n.val());
return vfact[n.val()];
}
Vector<Modulo> facts(Modulo n) {
resize(n.val());
return vfact[{0, n.val(), 1}];
}
Modulo factinv(Modulo n) {
resize(n.val());
return ifact[n.val()];
}
Vector<Modulo> factinvs(Modulo n) {
resize(n.val());
return ifact[{0, n.val(), 1}];
}
Modulo power(Modulo n) {
resize(n.val());
return pows[n.val()];
}
Vector<Modulo> powers(Modulo n) {
resize(n.val());
return pows[{0, n.val(), 1}];
}
Modulo parm(Modulo n, Modulo r) {
if (n < r)
return Modulo();
resize(n.val());
return vfact[n.val()] * ifact[(n - r).val()];
}
Modulo comb(Modulo n, Modulo r) {
if (n < r)
return Modulo();
resize(n.val());
return vfact[n.val()] * ifact[(n - r).val()] * ifact[r.val()];
}
Modulo homo(Modulo n, Modulo r) { return comb(n + r - 1, r); }
};
// Eratos class need Vector class
class Eratos {
Vector<int> divs, prms, ords;
int order_max;
public:
Eratos(int n = 0) : order_max(0) { resize(n); }
int size() const { return divs.size(); }
void resize(int n) {
if (size() >= n)
return;
int m = size();
divs.resize(n + 1);
for (int i = m; i < 2; i++)
if (i < size())
divs[i] = -1;
int r = std::sqrt(n - 1) + 1;
for (int i = 2; i < r; i++)
if (divs[i] == 0)
for (int j = std::max((m - 1) / i + 1, (int)2) * i; j <= n; j += i)
divs[j] = (divs[j] == 0 ? i : divs[j]);
for (int i = m; i <= n; i++)
if (divs[i] == 0)
prms.pub(i);
ords.resize(n + 1);
for (int i = m; i <= n; i++)
ords[i] = (divs[i] == 0 ? ++order_max : 0);
}
Vector<int> divisors() const { return divs; }
Vector<int> primes() const { return prms; }
Vector<int> orders() const { return ords; }
};
// Unionfind class need Vector class
template <typename T> class Unionfind {
Vector<int> p;
Vector<T> w;
int sign(int x) { return (x > 0) - (x < 0); }
int get(int x) {
if (p[x] == (x + 1))
return x + 1;
else {
int parent = sign(p[x]) * get(abs(p[x]) - 1);
w[x] += w[abs(p[x]) - 1];
return p[x] = parent;
}
}
void get(int &x, int &y) {
x = get(x);
y = get(y);
}
int weight(int x) {
get(x);
return w[x];
}
public:
Unionfind(int n = 0) { resize(n); }
void resize(const int &n) {
p.resize(n);
for (int i = w.size(); i < p.size(); i++)
p[i] = i + 1;
w.resize(n);
}
int size() const { return p.size(); }
bool unite(int x, int y, T vv = T()) {
if (vv < 0) {
std::swap(x, y);
vv *= -1;
}
vv += weight(x) - weight(y);
get(x, y);
if (abs(x) == abs(y))
return vv == weight(x) - weight(y);
p[abs(y) - 1] = x * sign(y);
w[abs(y) - 1] = vv;
return true;
}
bool separate(int x, int y, T vv = T()) {
if (vv < 0) {
std::swap(x, y);
vv *= -1;
}
vv += weight(x) - weight(y);
get(x, y);
if (abs(x) == abs(y))
return vv == weight(x) - weight(y);
p[abs(y) - 1] = -x * sign(y);
w[abs(y) - 1] = vv;
return true;
}
int same(int x, int y) {
get(x, y);
return (x == y) - (x == -y);
}
Vector<int> same(int x) {
Vector<int> v(size());
for (int i = 0; i < size(); i++)
v[i] = same(x, i);
return v;
}
T diff(int x, int y) { return sign(same(x, y)) * (weight(y) - weight(x)); }
Vector<T> diff(int x) {
Vector<int> v(size());
for (int i = 0; i < size(); i++)
v[i] = diff(x, i);
return v;
}
};
// Graph class need Vector class
template <typename T> struct Edge {
int from, to;
T cost;
Edge(int f = 0, int t = 0, T c = T()) : from(f), to(t), cost(c) {}
};
template <typename T> std::istream &operator>>(std::istream &i, Edge<T> &e) {
i >> e.from >> e.to >> e.cost;
return i;
}
template <typename T>
std::ostream &operator<<(std::ostream &o, const Edge<T> &e) {
return o << e.from << ' ' << e.to << ' ' << e.cost;
}
template <typename T> class Graph {
public:
Vector<Edge<T>> edge;
Vector<Vector<int>> node;
Graph(int n = 0) { resize(n); }
void resize(int n) { node.resize(n); }
void clear() {
edge = Vector<Edge<T>>();
node = Vector<Vector<int>>(nodes());
}
int edges() const { return edge.size(); }
int nodes() const { return node.size(); }
virtual int add(int from, int to, T cost) = 0;
Vector<T> dijkstra(int start) {
Vector<T> d(nodes(), std::numeric_limits<T>::max());
std::priority_queue<std::pair<T, int>, std::vector<std::pair<T, int>>,
std::greater<std::pair<T, int>>>
s;
d[start] = 0;
s.emplace(d[start], start);
while (!s.empty()) {
T dist = s.top().first;
int from = s.top().second;
s.pop();
if (d[from] < dist)
continue;
for (int id : node[from]) {
int to = edge[id].from ^ edge[id].to ^ from;
if (d[from] + edge[id].cost < d[to]) {
d[to] = d[from] + edge[id].cost;
s.emplace(d[to], to);
}
}
}
return d;
}
};
// Undigraph class need Vector, Graph class
template <typename T> class Undigraph : public Graph<T> {
Vector<int> brgs, crus, lows, ords;
bool lowlinked;
int lowlink_dfs(int from, int k, int parent) {
ords[from] = lows[from] = k++;
bool is_crunode = false;
int cnt = 0;
for (int id : node[from]) {
int to = edge[id].from ^ edge[id].to ^ from;
if (ords[to] == -1) {
cnt++;
k = lowlink_dfs(to, k, from);
lows[from] = std::min(lows[from], lows[to]);
is_crunode |= parent != -1 && lows[to] >= ords[from];
if (ords[from] < lows[to])
brgs.pub(id);
} else if (to != parent)
lows[from] = std::min(lows[from], lows[to]);
}
is_crunode |= parent == -1 && cnt > 1;
if (is_crunode)
crus.pub(from);
return k;
}
void lowlink() {
brgs = Vector<int>();
crus = Vector<int>();
ords.assign(this->nodes(), -1), lows.assign(this->nodes(), -1);
int k = 0;
for (int i = 0; i < this->nodes(); i++)
if (ords[i] == -1)
k = lowlink_dfs(i, k, -1);
lowlinked = true;
}
public:
using Graph<T>::edge;
using Graph<T>::node;
Undigraph(int n = 0) : Graph<T>(n) { lowlinked = false; }
int add(int from, int to, T cost = 1) {
int id = this->edges();
node[from].pub(id);
node[to].pub(id);
edge.pub(Edge<T>(from, to, cost));
return id;
}
void reset_lowlink() { lowlink(); }
Vector<int> bridges() {
if (!lowlinked)
lowlink();
return brgs;
}
Vector<int> crunodes() {
if (!lowlinked)
lowlink();
return crus;
}
T prim(int start = 0) {
Vector<std::pair<T, std::pair<int, int>>> cft;
T total = 0;
Vector<int> used(this->nodes(), 0);
std::priority_queue<std::pair<T, std::pair<int, int>>,
std::vector<std::pair<T, std::pair<int, int>>>,
std::greater<std::pair<T, std::pair<int, int>>>>
s;
s.emplace(std::make_pair(0, std::make_pair(-1, start)));
while (!s.empty()) {
T cost = s.top().first;
int fromfrom = s.top().second.first, from = s.top().second.second;
s.pop();
if (used[from])
continue;
used[from] = true;
total += cost;
if (fromfrom > -1)
cft.pub(std::make_pair(cost, std::make_pair(fromfrom, from)));
for (int id : node[from]) {
int to = edge[id].from ^ edge[id].to ^ from;
s.emplace(std::make_pair(edge[id].cost, std::make_pair(from, to)));
}
}
this->clear();
for (std::pair<T, std::pair<int, int>> e : cft)
add(e.second.first, e.second.second, e.first);
return total;
}
};
// Forest class need Vector, Graph, Undigraph class
template <typename T> class Forest : public Undigraph<T> {
public:
Vector<int> root, parent, treesize, depth;
Vector<T> dist;
Vector<Vector<int>> children;
using Undigraph<T>::edge;
using Undigraph<T>::node;
using Undigraph<T>::resize;
using Undigraph<T>::edges;
using Undigraph<T>::nodes;
Forest(int n = 0) : Undigraph<T>(n) { initialize(); }
void initialize() {
root.assign(nodes(), -1);
parent.assign(nodes(), -1);
treesize.assign(nodes(), 1);
depth.assign(nodes(), 0);
dist.assign(nodes(), 0);
children.assign(nodes(), Vector<int>());
}
private:
void dfs(int from) {
for (int &id : node[from]) {
if (from == edge[id].from)
std::swap(edge[id].from, edge[id].to);
int to = edge[id].from;
if (root[to] != -1)
continue;
root[to] = root[from];
parent[to] = from;
depth[to] = depth[from] + 1;
dist[to] = dist[from] + edge[id].cost;
children[from].pub(to);
dfs(to);
treesize[from] += treesize[to];
}
}
public:
void setTreeRoot(int n) {
initialize();
root[n] = n;
dfs(n);
}
void setForestRoot() {
initialize();
for (int n = 0; n < nodes(); n++)
if (root[n] == -1) {
root[n] = n;
dfs(n);
};
}
T diameter(int n = 0) {
setTreeRoot(n);
int terminal = dist.argmax();
setTreeRoot(terminal);
return dist.max();
}
};
// Digraph class need Vector, Graph class
template <typename T> class Digraph : public Graph<T> {
Vector<Vector<int>> rev_node;
Vector<Edge<T>> rev_edge;
Vector<int> strong_edgeid, weak_edgeid, strong_id, ords;
bool scced;
void scc_dfs(int from) {
if (strong_id[from] == -1)
return;
strong_id[from] = -1;
for (int id : node[from]) {
int to = edge[id].from ^ edge[id].to ^ from;
scc_dfs(to);
}
ords.pub(from);
}
void scc_rdfs(int from, int cnt) {
if (strong_id[from] != -1)
return;
strong_id[from] = cnt;
for (int id : rev_node[from]) {
int to = rev_edge[id].from ^ rev_edge[id].to ^ from;
if (strong_id[to] == -1) {
strong_edgeid.pub(id);
scc_rdfs(to, cnt);
} else if (strong_id[to] == cnt)
strong_edgeid.pub(id);
else if (strong_id[to] < cnt)
weak_edgeid.pub(id);
}
}
public:
using Graph<T>::edge;
using Graph<T>::node;
Digraph(int n = 0) : Graph<T>(n), scced(false) {}
int add(int from, int to, T cost = 1) {
int id = this->edges();
node[from].pub(id);
edge.pub(Edge<T>(from, to, cost));
return id;
}
Digraph<T> reversed() const {
Digraph<T> r(this->edges());
for (Edge<T> e : edge)
r.add(e.to, e.from, e.cost);
return r;
}
void scc() {
strong_edgeid = Vector<int>();
weak_edgeid = Vector<int>();
strong_id.assign(this->nodes(), 0);
ords = Vector<int>(this->nodes());
rev_node = Vector<Vector<int>>(this->nodes());
rev_edge = Vector<Edge<T>>(this->edges());
for (int id = 0; id < this->edges(); id++) {
rev_node[edge[id].to].pub(id);
rev_edge[id] = Edge<T>(edge[id].to, edge[id].from, edge[id].cost);
}
for (int from = 0; from < this->nodes(); from++)
scc_dfs(from);
ords.reverse();
int cnt = 0;
for (int from : ords)
if (strong_id[from] == -1) {
scc_rdfs(from, cnt);
cnt++;
}
Vector<Edge<T>> strong_edge;
for (int id : strong_edgeid)
strong_edge.pub(edge[id]);
this->clear();
for (Edge<T> e : strong_edge)
add(e.from, e.to, e.cost);
scced = true;
}
Vector<int> weakid() {
if (!scced)
scc();
return weak_edgeid;
};
Vector<int> stronggroup() {
if (!scced)
scc();
return strong_id;
}
Vector<T> bellman(int start) {
Vector<T> d(this->nodes(), std::numeric_limits<T>::max());
d[start] = 0;
bool negloop = false;
Vector<int> updating(1, start);
for (int i = 0; i < this->nodes() && updating.size() > 0; i++) {
Vector<int> toUpdate;
for (int from : updating) {
for (int id : node[from]) {
int to = edge[id].from ^ edge[id].to ^ from;
if (d[to] > d[from] + edge[id].cost) {
d[to] = d[from] + edge[id].cost;
toUpdate.pub(to);
if (i == this->nodes() - 1)
d[to] = std::numeric_limits<T>::min();
negloop = true;
}
}
}
updating = toUpdate;
}
if (negloop) {
for (int i = 0; i < this->nodes() && updating.size() > 0; i++) {
Vector<int> toUpdate;
for (int from : updating) {
for (int id : node[from]) {
int to = edge[id].from ^ edge[id].to ^ from;
if (d[to] != std::numeric_limits<T>::min()) {
d[to] = std::numeric_limits<T>::min();
toUpdate.pub(to);
}
}
}
updating = toUpdate;
}
}
return d;
}
Vector<int> topsort() {
Vector<int> to_node(this->nodes(), 0);
for (Edge<T> e : edge)
to_node[e.to]++;
Vector<int> sorted;
for (int i = 0; i < this->nodes(); i++)
if (to_node[i] == 0)
sorted.pub(i);
for (int i = 0; i < sorted.size(); i++)
for (int id : node[sorted[i]]) {
if (--to_node[edge[id].to] == 0)
sorted.pub(edge[id].to);
}
if (sorted.size() != this->nodes())
return Vector<int>();
return sorted;
}
};
// math function for Vector, Matrix, Modulo class
template <typename T> T sign(const T &x) { return (x > 0) - (x < 0); }
template <typename T> T abs(const T &x) { return x * sign(x); }
template <typename T> T power(T x, int y) {
T r = x * 0 + 1;
while (y > 0) {
if (y & 1)
r *= x;
x *= x;
y /= 2;
}
return r;
}
bool is_power(int n, int m) {
return n == power(llround(std::pow(n, (double)+1 / m)), m);
}
int _gcd(const int &a, const int &b) { return b ? _gcd(b, a % b) : a; }
int gcd(const int &a, const int &b) {
return _gcd(std::max(a, b), std::min(a, b));
}
int lcm(const int &a, const int &b) { return a / gcd(a, b) * b; }
bool is_prime(int n) {
int m = std::sqrt(n - 1) + 1;
for (int i = 2; i < m + 1; i++)
if (n % i == 0)
return false;
return n > 1;
}
int fact(int n) {
int v = 1;
for (int i = 1; i < n + 1; i++)
v *= i;
return v;
}
Modulo fact(Modulo n) {
Modulo v = 1;
for (int i = 1; i < n + 1; i++)
v *= i;
return v;
}
int parm(int n, int r) {
int v = 1;
for (int i = n - r + 1; i < n + 1; i++)
v *= i;
return v;
}
Modulo parm(Modulo n, Modulo r) {
Modulo v = 1;
for (int i = n.val() - r.val() + 1; i < n.val() + 1; i++)
v *= i;
return v;
}
int comb(int n, int r) {
int v = 1;
r = std::min(r, n - r);
for (int i = 0; i < r; i++) {
v *= n - i;
v /= i + 1;
}
return v;
}
Modulo comb(Modulo n, Modulo r) {
Modulo p = 1, q = 1;
r = std::min(r, n - r);
for (int i = 0; i < r; i++) {
p *= n - i;
q *= i + 1;
}
return p / q;
}
int homo(int m, int n) { return comb(m + n - 1, n); }
Modulo homo(Modulo m, Modulo n) { return comb(m + n - 1, n); }
// ex. function_find(fname,0,1024,'u',100,output)
#define function_find(FUNCTION_INT_TO_VALUE, INT_RANGE_MIN, INT_RANGE_MAX, \
CHAR_KIND, VALUE_TARGET, INT_AND_OUTPUT) \
{ \
int left = INT_RANGE_MIN - 1; \
int right = INT_RANGE_MAX + 1; \
bool outleft = (CHAR_KIND == 'd' || CHAR_KIND == 'U'); \
int getmin = (CHAR_KIND == 'u' || CHAR_KIND == 'd') ? 1 : -1; \
while (right - left > 1) { \
int mid = left + (right - left) / 2; \
bool OK = FUNCTION_INT_TO_VALUE(mid) * getmin >= VALUE_TARGET * getmin; \
if (outleft == OK) \
left = mid; \
else \
right = mid; \
} \
INT_AND_OUTPUT = outleft ? left : right; \
}
// BinaryIndexedTree class need Vector class
#define BITCalc(OP) \
BinaryIndexedTree<T> operator OP##=(const T &v) { \
if (range.first + 1 == range.second) \
for (int i = range.first; i < size(); i |= (i + 1)) \
t1[i] OP## = v; \
else \
for (int i = range.first; i < size(); i |= (i + 1)) { \
t1[i] OP## = -v * (range.first - 1); \
t2[i] OP## = v; \
} \
for (int i = range.second; i < size(); i |= (i + 1)) { \
t1[i] OP## = v * (range.second - 1); \
t2[i] OP## = -v; \
} \
return *this; \
}
template <typename T> class BinaryIndexedTree {
Vector<T> t1, t2;
std::pair<int, int> range;
public:
T sum(int x) {
T v = T();
for (int i = x; i >= 0; i = (i & (i + 1)) - 1) {
v += t1[i] + t2[i] * x;
}
return v;
}
T sum(int l, int r) { return sum(r - 1) - sum(l - 1); }
T get(int x) { return sum(x, x + 1); }
void resize(int n) {
t1.resize(n);
t2.resize(n);
}
int size() const { return t1.size(); }
Vector<T> firstVector() const { return t1; }
Vector<T> secondVector() const { return t2; }
BinaryIndexedTree(int n = 0) : range(std::make_pair(0, 0)) { resize(n); }
BinaryIndexedTree(const BinaryIndexedTree &bit)
: t1(bit.firstVector()), t2(bit.secondVector()),
range(std::make_pair(0, -1)) {
resize(bit.size());
}
BinaryIndexedTree<T> &operator=(const BinaryIndexedTree<T> &bit) {
resize(bit.size());
t1 = bit.firstVector();
t2 = bit.secondVector();
return *this;
}
T operator[](int i) const { return get(i); }
BinaryIndexedTree<T> &operator[](std::initializer_list<int> l) {
if (l.size() == 1) {
range.first = *l.begin();
range.second = (*l.begin()) + 1;
}
if (l.size() == 2) {
range.first = *l.begin();
range.second = (*(l.begin() + 1) < 0 ? *(l.begin() + 1) + size() + 1
: *(l.begin() + 1));
}
return *this;
}
BITCalc(+) BITCalc(-) T sum() { return sum(range.first, range.second); }
BinaryIndexedTree<T> operator=(const T &v) {
for (int i = range.first; i < range.second; i++) {
operator[]({i});
operator+=(-get(i) + v);
}
return *this;
}
Vector<T> toVector() {
Vector<T> v(size());
for (int i = 0; i < size(); i++)
v[i] = get(i);
return v;
}
};
class Input {
public:
template <typename T> void input_integer(T &var) {
var = 0;
T sign = 1;
int c = getchar_unlocked();
while (!(('0' <= c && c <= '9') || c == '-'))
c = getchar_unlocked();
if (c == '-') {
sign = -1;
c = getchar_unlocked();
}
while ('0' <= c && c <= '9') {
var = var * 10 + c - '0';
c = getchar_unlocked();
}
var *= sign;
}
Input &operator>>(int32_t &var) {
input_integer<int32_t>(var);
return *this;
}
Input &operator>>(int64_t &var) {
input_integer<int64_t>(var);
return *this;
}
Input &operator>>(std::string &var) {
int c = getchar_unlocked();
while (!(0x21 <= c && c <= 0x7E))
c = getchar_unlocked();
while (0x21 <= c && c <= 0x7E) {
var.push_back(c);
c = getchar_unlocked();
}
return *this;
}
};
Input input;
// BIT^2, graph
// argofsortup
// 10^5 -> NlogN, 3000 -> N^2, 200 -> N^3, 50 -> N^4, 20 -> 2^N
WRITE_FUNCTION_UNDER_HERE
int32_t main() {
INIT;
in(int, n, m);
VPII py(m);
fou(i, 0, py.size()) { cin >> py[i].fi >> py[i].se; }
VI order(m);
order.iota();
order = separate((unite(py, order)).sortuped()).se;
py.sortup();
py[0].se = 1;
fou(i, 1, py.size()) {
if (py[i].fi == py[i - 1].fi) {
py[i].se = py[i - 1].se + 1;
} else {
py[i].se = 1;
}
}
py = separate((unite(order, py)).sortuped()).se;
fou(i, 0, py.size()) {
String pref = py[i].fi;
while (pref.size() < 6)
pref.insert(0, '0');
String year = py[i].se;
while (year.size() < 6)
year.insert(0, '0');
out(pref + year);
}
} | replace | 2,139 | 2,140 | 2,139 | 2,140 | TLE | |
p03221 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
vector<int> P(M);
vector<int> Y(M);
map<int, vector<int>> PY;
for (auto i = 0; i < M; i++) {
cin >> P[i] >> Y[i];
if (PY.find(P[i]) == PY.end()) {
vector<int> tmp;
PY[P[i]] = tmp;
}
PY[P[i]].push_back(Y[i]);
}
for (auto iter = PY.begin(); iter != PY.end(); iter++)
sort(iter->second.begin(), iter->second.end());
for (auto i = 0; i < M; i++) {
cout << setw(6) << setfill('0') << P[i];
cout << setw(6) << setfill('0')
<< find(PY[P[i]].begin(), PY[P[i]].end(), Y[i]) - PY[P[i]].begin() + 1
<< endl;
}
return 0;
} | #include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
vector<int> P(M);
vector<int> Y(M);
map<int, vector<int>> PY;
for (auto i = 0; i < M; i++) {
cin >> P[i] >> Y[i];
if (PY.find(P[i]) == PY.end()) {
vector<int> tmp;
PY[P[i]] = tmp;
}
PY[P[i]].push_back(Y[i]);
}
for (auto iter = PY.begin(); iter != PY.end(); iter++)
sort(iter->second.begin(), iter->second.end());
for (auto i = 0; i < M; i++) {
cout << setw(6) << setfill('0') << P[i];
cout << setw(6) << setfill('0')
<< lower_bound(PY[P[i]].begin(), PY[P[i]].end(), Y[i]) -
PY[P[i]].begin() + 1
<< endl;
}
return 0;
} | replace | 30 | 31 | 30 | 32 | TLE | |
p03221 | C++ | Runtime Error | #define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <string>
#include <vector>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)
using namespace std;
using ll = long long;
typedef pair<ll, ll> p;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
const long long mod = 1e9 + 7;
ll gcd(ll a, ll b);
ll lcm(ll a, ll b);
int main() {
ll N, M;
cin >> N >> M;
vector<p> C, ans;
vector<vector<ll>> H(N + 1);
ll P, Y;
rep(i, M) {
cin >> P >> Y;
C.emplace_back(P, Y);
H[P].push_back(Y);
}
rep(i, M) { sort(H[i].begin(), H[i].end()); }
rep(i, M) {
P = C[i].first;
Y = find(H[P].begin(), H[P].end(), C[i].second) - H[P].begin() + 1;
ans.emplace_back(P, Y);
}
char fillSaved = cout.fill('0');
rep(i, M) {
cout << setw(6) << ans[i].first << setw(6) << ans[i].second << endl;
}
cout.fill(fillSaved);
return 0;
}
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); } | #define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <string>
#include <vector>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)
using namespace std;
using ll = long long;
typedef pair<ll, ll> p;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
const long long mod = 1e9 + 7;
ll gcd(ll a, ll b);
ll lcm(ll a, ll b);
int main() {
ll N, M;
cin >> N >> M;
vector<p> C, ans;
vector<vector<ll>> H(N + 1);
ll P, Y;
rep(i, M) {
cin >> P >> Y;
C.emplace_back(P, Y);
H[P].push_back(Y);
}
rep(i, N + 1) { sort(H[i].begin(), H[i].end()); }
rep(i, M) {
P = C[i].first;
Y = find(H[P].begin(), H[P].end(), C[i].second) - H[P].begin() + 1;
ans.emplace_back(P, Y);
}
char fillSaved = cout.fill('0');
rep(i, M) {
cout << setw(6) << ans[i].first << setw(6) << ans[i].second << endl;
}
cout.fill(fillSaved);
return 0;
}
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); } | replace | 53 | 54 | 53 | 54 | 0 | |
p03221 | C++ | Runtime Error | #include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<int> p(n), y(n);
for (int i = 0; i < m; i++)
cin >> p[i] >> y[i];
vector<vector<int>> cor(n + 1); // cor[p[i]] = 県p[i]に属する市の誕生年の配列
for (int i = 0; i < m; i++)
cor[p[i]].push_back(y[i]);
for (int i = 1; i <= n; i++)
sort(cor[i].begin(), cor[i].end());
for (int i = 0; i < m; i++) {
int num = lower_bound(cor[p[i]].begin(), cor[p[i]].end(), y[i]) -
cor[p[i]].begin() + 1;
printf("%06d%06d\n", p[i], num);
}
return 0;
} | #include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<int> p(m), y(m);
for (int i = 0; i < m; i++)
cin >> p[i] >> y[i];
vector<vector<int>> cor(n + 1); // cor[p[i]] = 県p[i]に属する市の誕生年の配列
for (int i = 0; i < m; i++)
cor[p[i]].push_back(y[i]);
for (int i = 1; i <= n; i++)
sort(cor[i].begin(), cor[i].end());
for (int i = 0; i < m; i++) {
int num = lower_bound(cor[p[i]].begin(), cor[p[i]].end(), y[i]) -
cor[p[i]].begin() + 1;
printf("%06d%06d\n", p[i], num);
}
return 0;
} | replace | 7 | 8 | 7 | 8 | 0 | |
p03221 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
string add0(int X) {
string S = to_string(X);
while (S.size() < 6) {
S = '0' + S;
}
return S;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N, M;
cin >> N >> M;
vector<int> P(M), Y(M);
vector<vector<int>> V(N);
for (int i = 0; i < M; ++i) {
cin >> P.at(i) >> Y.at(i);
V.at(P.at(i) - 1).push_back(Y.at(i));
}
for (auto &A : V) {
sort(A.begin(), A.end());
}
for (int i = 0; i < M; ++i) {
auto A = V.at(P.at(i) - 1);
int res = lower_bound(A.begin(), A.end(), Y.at(i)) - A.begin() + 1;
cout << setfill('0') << right << setw(6) << P.at(i);
cout << setfill('0') << right << setw(6) << res << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
string add0(int X) {
string S = to_string(X);
while (S.size() < 6) {
S = '0' + S;
}
return S;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N, M;
cin >> N >> M;
vector<int> P(M), Y(M);
vector<vector<int>> V(N);
for (int i = 0; i < M; ++i) {
cin >> P.at(i) >> Y.at(i);
V.at(P.at(i) - 1).push_back(Y.at(i));
}
for (auto &A : V) {
sort(A.begin(), A.end());
}
for (int i = 0; i < M; ++i) {
auto &A = V.at(P.at(i) - 1);
int res = lower_bound(A.begin(), A.end(), Y.at(i)) - A.begin() + 1;
cout << setfill('0') << right << setw(6) << P.at(i);
cout << setfill('0') << right << setw(6) << res << endl;
}
return 0;
} | replace | 29 | 30 | 29 | 30 | TLE | |
p03221 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define RREP(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, k, n) for (int i = (k); i < (int)(n); i++)
#define all(i, n) (i), (i + n)
int dx4[4] = {1, 0, -1, 0};
int dy4[4] = {0, -1, 0, 1};
int dx8[8] = {1, 0, -1, 1, -1, 1, 0, -1};
int dy8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6 + 1;
const ll mod = 1000000007;
// --------------------------------------
int n, m;
priority_queue<P, vector<P>, greater<P>> que;
vector<vector<int>> v;
vector<P> pv;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n >> m;
v.reserve(n + 1);
REP(i, m) {
int a, b;
cin >> a >> b;
v[a].push_back(b);
pv.push_back(make_pair(a, b));
}
FOR(i, 1, n + 1) {
if (v[i].size() > 0) {
sort(v[i].begin(), v[i].end());
}
}
REP(i, m) {
P p = pv[i];
auto pp = find(v[p.first].begin(), v[p.first].end(), p.second);
cout << setw(6) << setfill('0') << p.first;
cout << setw(6) << setfill('0') << (pp - v[p.first].begin() + 1) << endl;
}
}
| #include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define RREP(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, k, n) for (int i = (k); i < (int)(n); i++)
#define all(i, n) (i), (i + n)
int dx4[4] = {1, 0, -1, 0};
int dy4[4] = {0, -1, 0, 1};
int dx8[8] = {1, 0, -1, 1, -1, 1, 0, -1};
int dy8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6 + 1;
const ll mod = 1000000007;
// --------------------------------------
int n, m;
priority_queue<P, vector<P>, greater<P>> que;
vector<vector<int>> v;
vector<P> pv;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n >> m;
v.reserve(n + 1);
REP(i, m) {
int a, b;
cin >> a >> b;
v[a].push_back(b);
pv.push_back(make_pair(a, b));
}
FOR(i, 1, n + 1) {
if (v[i].size() > 0) {
sort(v[i].begin(), v[i].end());
}
}
REP(i, m) {
P p = pv[i];
auto pp = lower_bound(v[p.first].begin(), v[p.first].end(), p.second);
cout << setw(6) << setfill('0') << p.first;
cout << setw(6) << setfill('0') << (pp - v[p.first].begin() + 1) << endl;
}
}
| replace | 60 | 61 | 60 | 61 | TLE | |
p03221 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
void solve() {
int n, m;
cin >> n >> m;
unordered_map<int, vector<int>> mp;
vector<pair<int, int>> a(m);
for (int i = 0; i < m; i++) {
int p, y;
cin >> p >> y;
mp[p].push_back(y);
a[i].first = p;
a[i].second = y;
}
for (auto t = mp.begin(); t != mp.end(); t++) {
sort((*t).second.begin(), (*t).second.end());
}
for (int i = 0; i < m; i++) {
int p = a[i].first;
int y = a[i].second;
string s = to_string(p);
for (int j = 0; j < 6 - (int)s.size(); j++) {
cout << 0;
}
cout << s;
auto x = mp[p];
int l = 0, r = x.size() - 1;
string s2;
while (l <= r) {
int mid = l + (r - l);
if (x[mid] == y) {
s2 = to_string(mid + 1);
break;
} else if (x[mid] > y) {
r = mid - 1;
} else {
l = mid + 1;
}
}
for (int j = 0; j < 6 - (int)s2.size(); j++) {
cout << 0;
}
cout << s2 << "\n";
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
solve();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
void solve() {
int n, m;
cin >> n >> m;
unordered_map<int, vector<int>> mp;
vector<pair<int, int>> a(m);
for (int i = 0; i < m; i++) {
int p, y;
cin >> p >> y;
mp[p].push_back(y);
a[i].first = p;
a[i].second = y;
}
for (auto t = mp.begin(); t != mp.end(); t++) {
sort((*t).second.begin(), (*t).second.end());
}
for (int i = 0; i < m; i++) {
int p = a[i].first;
int y = a[i].second;
printf("%06d", p);
int l = lower_bound(mp[p].begin(), mp[p].end(), y) - mp[p].begin();
printf("%06d\n", l + 1);
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
solve();
return 0;
}
| replace | 21 | 44 | 21 | 24 | TLE | |
p03221 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
typedef int64_t ll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define vll vector<ll>
#define all(v) v.begin(), v.end()
int main() {
ll N, M;
cin >> N >> M;
vll P(M), Y(M);
rep(i, M) cin >> P[i] >> Y[i];
map<ll, vll> pref;
rep(i, M) pref[P[i]].push_back(Y[i]);
for (auto &p : pref)
sort(all(p.second));
rep(i, M) {
auto it = find(all(pref[P[i]]), Y[i]);
cout << setw(6) << setfill('0') << P[i];
cout << setw(6) << setfill('0') << (it - pref[P[i]].begin() + 1) << endl;
;
}
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
typedef int64_t ll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define vll vector<ll>
#define all(v) v.begin(), v.end()
int main() {
ll N, M;
cin >> N >> M;
vll P(M), Y(M);
rep(i, M) cin >> P[i] >> Y[i];
map<ll, vll> pref;
rep(i, M) pref[P[i]].push_back(Y[i]);
for (auto &p : pref)
sort(all(p.second));
rep(i, M) {
// auto it = find(all(pref[P[i]]), Y[i]);
ll ok = pref[P[i]].size();
ll ng = -1;
while (abs(ok - ng) > 1) {
ll mid = (ok + ng) / 2;
if (pref[P[i]][mid] < Y[i])
ng = mid;
else if (pref[P[i]][mid] > Y[i])
ok = mid;
else {
cout << setw(6) << setfill('0') << P[i];
cout << setw(6) << setfill('0') << mid + 1 << endl;
break;
}
}
}
} | replace | 35 | 39 | 35 | 50 | TLE | |
p03221 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <list>
#include <stdio.h>
#include <utility>
#include <vector>
using namespace std;
struct City {
int y;
int p;
int n;
};
int main() {
vector<City> city;
int N, M;
cin >> N >> M;
for (int i = 0; i < M; i++) {
int p, y;
City tmp;
cin >> p >> y;
tmp.y = y;
tmp.p = p;
tmp.n = i;
city.push_back(tmp);
}
std::sort(city.begin(), city.end(),
[](City a, City b) -> bool { return a.y < b.y; });
int id;
for (int p = 1; p <= N; p++) {
id = 1;
for (int i = 0; i < city.size(); i++) {
if (city[i].p == p) {
city[i].y = id;
id++;
}
}
}
std::sort(city.begin(), city.end(),
[](City a, City b) -> bool { return a.n < b.n; });
for (int i = 0; i < city.size(); i++) {
printf("%06d%06d\n", city[i].p, city[i].y);
}
} | #include <algorithm>
#include <iostream>
#include <list>
#include <stdio.h>
#include <utility>
#include <vector>
using namespace std;
struct City {
int y;
int p;
int n;
};
int main() {
vector<City> city;
int N, M;
cin >> N >> M;
for (int i = 0; i < M; i++) {
int p, y;
City tmp;
cin >> p >> y;
tmp.y = y;
tmp.p = p;
tmp.n = i;
city.push_back(tmp);
}
std::sort(city.begin(), city.end(),
[](City a, City b) -> bool { return a.y < b.y; });
vector<int> id(N + 1, 1);
for (int i = 0; i < city.size(); i++) {
city[i].y = id[city[i].p];
id[city[i].p]++;
}
std::sort(city.begin(), city.end(),
[](City a, City b) -> bool { return a.n < b.n; });
for (int i = 0; i < city.size(); i++) {
printf("%06d%06d\n", city[i].p, city[i].y);
}
} | replace | 34 | 43 | 34 | 38 | TLE | |
p03221 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <string>
using namespace std;
struct ci {
int order;
int p;
int y;
bool operator<(const ci &another) const {
return y < another.y; // 年齢を比較
};
int id;
};
bool cmp(const ci &a, const ci &b) { return a.order < b.order; }
int main(void) {
int N, M;
struct ci c[1000];
int c_num[1000];
cin >> N >> M;
for (int i = 0; i < M; i++) {
cin >> c[i].p >> c[i].y;
c[i].order = i;
}
for (int i = 0; i < N; i++)
c_num[i] = 1;
sort(c, c + M);
for (int i = 0; i < M; i++) {
c[i].id = c_num[c[i].p - 1];
c_num[c[i].p - 1]++;
}
sort(c, c + M, cmp);
for (int i = 0; i < M; i++) {
printf("%06d%06d\n", c[i].p, c[i].id);
}
return 0;
}
| #include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <string>
using namespace std;
struct ci {
int order;
int p;
int y;
bool operator<(const ci &another) const {
return y < another.y; // 年齢を比較
};
int id;
};
bool cmp(const ci &a, const ci &b) { return a.order < b.order; }
int main(void) {
int N, M;
struct ci c[100000];
int c_num[100000];
cin >> N >> M;
for (int i = 0; i < M; i++) {
cin >> c[i].p >> c[i].y;
c[i].order = i;
}
for (int i = 0; i < N; i++)
c_num[i] = 1;
sort(c, c + M);
for (int i = 0; i < M; i++) {
c[i].id = c_num[c[i].p - 1];
c_num[c[i].p - 1]++;
}
sort(c, c + M, cmp);
for (int i = 0; i < M; i++) {
printf("%06d%06d\n", c[i].p, c[i].id);
}
return 0;
}
| replace | 18 | 20 | 18 | 20 | 0 | |
p03221 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
int n, m;
cin >> n >> m;
vector<vector<int>> v(n);
vector<pair<int, int>> per(n);
rep(i, m) {
int x, y;
cin >> x >> y;
x--;
v[x].push_back(y);
per[i] = {x + 1, y};
}
rep(i, n) {
if (v[i].size() == 0)
continue;
sort(v[i].begin(), v[i].end());
}
rep(i, m) {
int x, y;
x = per[i].first;
y = per[i].second;
printf("%06d", x);
printf("%06d\n", int(lower_bound(v[x - 1].begin(), v[x - 1].end(), y) -
v[x - 1].begin()) +
1);
}
// printf("%06d",100000);
return 0;
}
| #include <algorithm>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
int n, m;
cin >> n >> m;
vector<vector<int>> v(n);
vector<pair<int, int>> per(m);
rep(i, m) {
int x, y;
cin >> x >> y;
x--;
v[x].push_back(y);
per[i] = {x + 1, y};
}
rep(i, n) {
if (v[i].size() == 0)
continue;
sort(v[i].begin(), v[i].end());
}
rep(i, m) {
int x, y;
x = per[i].first;
y = per[i].second;
printf("%06d", x);
printf("%06d\n", int(lower_bound(v[x - 1].begin(), v[x - 1].end(), y) -
v[x - 1].begin()) +
1);
}
// printf("%06d",100000);
return 0;
}
| replace | 13 | 14 | 13 | 14 | 0 | |
p03221 | C++ | Runtime Error | #define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
using ll = long long;
using namespace std;
void solve() {
int n, m;
cin >> n >> m;
vector<int> pre[10000];
int p[10000], y[10000];
for (int i = 0; i < m; i++)
cin >> p[i] >> y[i], pre[p[i]].push_back(y[i]);
for (int i = 0; i < n; i++)
sort(pre[i + 1].begin(), pre[i + 1].end());
for (int i = 0; i < m; i++) {
ll final = (ll)p[i] * 1000000 +
ll(lower_bound(pre[p[i]].begin(), pre[p[i]].end(), y[i]) -
pre[p[i]].begin()) +
1;
printf("%012lld\n", final);
}
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(NULL);
int test;
test = 1;
while (test--) {
solve();
}
return 0;
} | #define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
using ll = long long;
using namespace std;
void solve() {
int n, m;
cin >> n >> m;
vector<int> pre[100001];
int p[100000], y[100000];
for (int i = 0; i < m; i++)
cin >> p[i] >> y[i], pre[p[i]].push_back(y[i]);
for (int i = 0; i < n; i++)
sort(pre[i + 1].begin(), pre[i + 1].end());
for (int i = 0; i < m; i++) {
ll final = (ll)p[i] * 1000000 +
ll(lower_bound(pre[p[i]].begin(), pre[p[i]].end(), y[i]) -
pre[p[i]].begin()) +
1;
printf("%012lld\n", final);
}
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(NULL);
int test;
test = 1;
while (test--) {
solve();
}
return 0;
} | replace | 11 | 13 | 11 | 13 | 0 | |
p03221 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long int ll;
#define repi(i, a, b) for (ll i = a; i < b; i++)
#define rep(i, a) repi(i, 0, a)
#define all(u) u.begin(), u.end()
#define pl pair<ll, ll>
#define fi first
#define se second
#define inf 1000000007
ll N, M;
vector<pl> city;
vector<ll> Data[100010];
ll keta(ll n) {
ll res = 0;
while (n / 10 != 0) {
res++;
n /= 10;
}
return res;
}
int main() {
scanf("%lld%lld", &N, &M);
rep(i, M) {
ll P, Y;
scanf("%lld%lld", &P, &Y);
pl temp;
temp.fi = P;
temp.se = Y;
city.push_back(temp);
Data[P].push_back(Y);
}
rep(i, 100010) {
if (Data[i].size() != 0) {
sort(Data[i].begin(), Data[i].end());
}
}
rep(i, M) {
ll x;
ll f = city[i].fi;
ll s = city[i].se;
rep(j, Data[f].size()) {
if (Data[f][j] == s) {
x = j + 1;
break;
}
}
string str;
string strr;
ll k = keta(f);
ll K = keta(x);
rep(j, 6 - k - 1) str += "0";
rep(j, 6 - K - 1) strr += "0";
cout << str << city[i].fi << strr << x << endl;
}
return 0;
}
| #include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long int ll;
#define repi(i, a, b) for (ll i = a; i < b; i++)
#define rep(i, a) repi(i, 0, a)
#define all(u) u.begin(), u.end()
#define pl pair<ll, ll>
#define fi first
#define se second
#define inf 1000000007
ll N, M;
vector<pl> city;
vector<ll> Data[100010];
ll keta(ll n) {
ll res = 0;
while (n / 10 != 0) {
res++;
n /= 10;
}
return res;
}
int main() {
scanf("%lld%lld", &N, &M);
rep(i, M) {
ll P, Y;
scanf("%lld%lld", &P, &Y);
pl temp;
temp.fi = P;
temp.se = Y;
city.push_back(temp);
Data[P].push_back(Y);
}
rep(i, 100010) {
if (Data[i].size() != 0) {
sort(Data[i].begin(), Data[i].end());
}
}
rep(i, M) {
ll x;
ll f = city[i].fi;
ll s = city[i].se;
x = lower_bound(Data[f].begin(), Data[f].end(), s) - Data[f].begin() + 1;
string str;
string strr;
ll k = keta(f);
ll K = keta(x);
rep(j, 6 - k - 1) str += "0";
rep(j, 6 - K - 1) strr += "0";
cout << str << city[i].fi << strr << x << endl;
}
return 0;
}
| replace | 54 | 60 | 54 | 55 | TLE | |
p03221 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;
int main() {
int N, M;
cin >> N >> M;
vector<pair<pint, int>> data(M);
vector<string> ans(M);
REP(i, M) {
int p, y;
cin >> p >> y;
data[i] = make_pair(make_pair(p, y), i);
}
sort(data.begin(), data.end());
int num = 0;
REP(i, M) {
if (i == 0 || data[i].first.first != data[i - 1].first.first) {
num = 1;
} else {
num++;
}
static char id[10];
sprintf(id, "%06d%06d", data[i].first.first, num);
ans[data[i].second] = string(id);
}
REP(i, M) { cout << ans[i] << endl; }
return 0;
}
| #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;
int main() {
int N, M;
cin >> N >> M;
vector<pair<pint, int>> data(M);
vector<string> ans(M);
REP(i, M) {
int p, y;
cin >> p >> y;
data[i] = make_pair(make_pair(p, y), i);
}
sort(data.begin(), data.end());
int num = 0;
REP(i, M) {
if (i == 0 || data[i].first.first != data[i - 1].first.first) {
num = 1;
} else {
num++;
}
static char id[100];
sprintf(id, "%06d%06d", data[i].first.first, num);
ans[data[i].second] = string(id);
}
REP(i, M) { cout << ans[i] << endl; }
return 0;
}
| replace | 31 | 32 | 31 | 32 | 0 | |
p03221 | C++ | Time Limit Exceeded | #include "bits/stdc++.h"
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<VVLL> VVVLL;
#define SORT_ASC(c) sort((c).begin(), (c).end())
#define SORT_DESC(c) \
sort((c).begin(), (c).end(), greater<typeof((c).begin())>())
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SIZE(a) int((a).size())
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INT_LARGE = 1000000100;
// debug func
template <typename T> void vecprint(vector<T> v) {
for (auto x : v) {
cerr << x << " ";
}
cerr << endl;
}
template <typename T> void vecvecprint(vector<vector<T>> vv) {
REP(i, SIZE(vv)) {
REP(j, SIZE(vv[i])) { cerr << vv[i][j] << " "; }
cerr << endl;
}
}
template <typename T> void pqprint(priority_queue<T> q) {
while (!q.empty()) {
cerr << q.top() << " ";
q.pop();
}
cerr << endl;
}
template <typename T> void qprint(queue<T> q) {
while (!q.empty()) {
cerr << q.front() << " ";
q.pop();
}
cerr << endl;
}
template <typename T> void vecqprint(vector<queue<T>> v) {
for (int i = 0; i < v.size(); i++) {
qprint(v[i]);
}
}
template <typename Iterator>
inline bool next_combination(const Iterator first, Iterator k,
const Iterator last) {
/* Credits: Thomas Draper */
if ((first == last) || (first == k) || (last == k))
return false;
Iterator itr1 = first;
Iterator itr2 = last;
++itr1;
if (last == itr1)
return false;
itr1 = last;
--itr1;
itr1 = k;
--itr2;
while (first != itr1) {
if (*--itr1 < *itr2) {
Iterator j = k;
while (!(*itr1 < *j))
++j;
iter_swap(itr1, j);
++itr1;
++j;
itr2 = k;
rotate(itr1, j, last);
while (last != j) {
++j;
++itr2;
}
rotate(k, itr2, last);
return true;
}
}
rotate(first, k, last);
return false;
}
inline double get_time_sec(void) {
return static_cast<double>(chrono::duration_cast<chrono::nanoseconds>(
chrono::steady_clock::now().time_since_epoch())
.count()) /
1000000000;
}
template <typename T> T gcd(T a, T b) {
if (a > b)
swap(a, b);
if (a == 0)
return b;
else
return gcd(b % a, a);
}
template <typename T> map<T, T> prime_list(T n) {
map<T, T> ret;
for (T i = 2; i * i <= n; i++) {
if (n % i == 0) {
ret[i] = 0;
while (n % i == 0) {
n /= i;
ret[i]++;
}
}
}
if (n != 1)
ret[n]++;
return ret;
}
int main(void) {
int n, m;
cin >> n >> m;
VI p(m, 0), y(m, 0);
VVI db(n + 1);
REP(i, m) {
cin >> p[i] >> y[i];
db[p[i]].push_back(y[i]);
}
FOR(i, 1, n + 1) { sort(db[i].begin(), db[i].end()); }
REP(i, m) {
REP(j, db[p[i]].size()) {
if (y[i] == db[p[i]][j]) {
cout << setw(6) << setfill('0') << p[i] << setw(6) << setfill('0')
<< (j + 1) << endl;
break;
}
}
}
} | #include "bits/stdc++.h"
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<VVLL> VVVLL;
#define SORT_ASC(c) sort((c).begin(), (c).end())
#define SORT_DESC(c) \
sort((c).begin(), (c).end(), greater<typeof((c).begin())>())
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SIZE(a) int((a).size())
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INT_LARGE = 1000000100;
// debug func
template <typename T> void vecprint(vector<T> v) {
for (auto x : v) {
cerr << x << " ";
}
cerr << endl;
}
template <typename T> void vecvecprint(vector<vector<T>> vv) {
REP(i, SIZE(vv)) {
REP(j, SIZE(vv[i])) { cerr << vv[i][j] << " "; }
cerr << endl;
}
}
template <typename T> void pqprint(priority_queue<T> q) {
while (!q.empty()) {
cerr << q.top() << " ";
q.pop();
}
cerr << endl;
}
template <typename T> void qprint(queue<T> q) {
while (!q.empty()) {
cerr << q.front() << " ";
q.pop();
}
cerr << endl;
}
template <typename T> void vecqprint(vector<queue<T>> v) {
for (int i = 0; i < v.size(); i++) {
qprint(v[i]);
}
}
template <typename Iterator>
inline bool next_combination(const Iterator first, Iterator k,
const Iterator last) {
/* Credits: Thomas Draper */
if ((first == last) || (first == k) || (last == k))
return false;
Iterator itr1 = first;
Iterator itr2 = last;
++itr1;
if (last == itr1)
return false;
itr1 = last;
--itr1;
itr1 = k;
--itr2;
while (first != itr1) {
if (*--itr1 < *itr2) {
Iterator j = k;
while (!(*itr1 < *j))
++j;
iter_swap(itr1, j);
++itr1;
++j;
itr2 = k;
rotate(itr1, j, last);
while (last != j) {
++j;
++itr2;
}
rotate(k, itr2, last);
return true;
}
}
rotate(first, k, last);
return false;
}
inline double get_time_sec(void) {
return static_cast<double>(chrono::duration_cast<chrono::nanoseconds>(
chrono::steady_clock::now().time_since_epoch())
.count()) /
1000000000;
}
template <typename T> T gcd(T a, T b) {
if (a > b)
swap(a, b);
if (a == 0)
return b;
else
return gcd(b % a, a);
}
template <typename T> map<T, T> prime_list(T n) {
map<T, T> ret;
for (T i = 2; i * i <= n; i++) {
if (n % i == 0) {
ret[i] = 0;
while (n % i == 0) {
n /= i;
ret[i]++;
}
}
}
if (n != 1)
ret[n]++;
return ret;
}
int main(void) {
int n, m;
cin >> n >> m;
VI p(m, 0), y(m, 0);
VVI db(n + 1);
REP(i, m) {
cin >> p[i] >> y[i];
db[p[i]].push_back(y[i]);
}
FOR(i, 1, n + 1) { sort(db[i].begin(), db[i].end()); }
REP(i, m) {
int id = (int)(lower_bound(db[p[i]].begin(), db[p[i]].end(), y[i]) -
db[p[i]].begin() + 1);
cout << setw(6) << setfill('0') << p[i] << setw(6) << setfill('0') << id
<< endl;
}
} | replace | 147 | 154 | 147 | 151 | TLE | |
p03221 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;
int main() {
ll n, m;
cin >> n >> m;
vector<ll> p(m), y(m);
vector<vector<ll>> yd(n + 1);
rep(i, m) cin >> p[i] >> y[i], yd[p[i]].push_back(y[i]);
rep(i, n) sort(yd[p[i + 1]].begin(), yd[p[i + 1]].end());
rep(i, m) printf("%06lld", p[i]),
printf("%06lld\n", lower_bound(yd[p[i]].begin(), yd[p[i]].end(), y[i]) -
yd[p[i]].begin() + 1LL);
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;
int main() {
ll n, m;
cin >> n >> m;
vector<ll> p(m), y(m);
vector<vector<ll>> yd(n + 1);
rep(i, m) cin >> p[i] >> y[i], yd[p[i]].push_back(y[i]);
rep(i, n) sort(yd[i + 1].begin(), yd[i + 1].end());
rep(i, m) printf("%06lld", p[i]),
printf("%06lld\n", lower_bound(yd[p[i]].begin(), yd[p[i]].end(), y[i]) -
yd[p[i]].begin() + 1LL);
}
| replace | 14 | 15 | 14 | 15 | 0 | |
p03221 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<pair<int, int>> hoge(m);
map<int, vector<int>> fuga;
for (int i = 0; i < m; i++) {
cin >> hoge.at(i).first >> hoge.at(i).second;
fuga[hoge.at(i).first].push_back(hoge.at(i).second);
}
for (auto a : hoge) {
sort(fuga[a.first].begin(), fuga[a.first].end());
}
for (auto at : hoge) {
int a = at.first;
int b = at.second;
int fst = a;
int ed = 0;
int left = 0;
int right = fuga[a].size() - 1;
while (left <= right) {
int mid = (left + right) / 2;
if (fuga[a].at(mid) == b) {
ed = mid + 1;
break;
} else if (fuga[a].at(mid) > b) {
right = mid - 1;
} else {
left = mid + 1;
}
}
string mae = to_string(fst);
string usiro = to_string(ed);
while (mae.size() < 6) {
mae = "0" + mae;
}
while (usiro.size() < 6) {
usiro = "0" + usiro;
}
cout << mae + usiro << endl;
}
return 0;
} | #include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<pair<int, int>> hoge(m);
map<int, vector<int>> fuga;
for (int i = 0; i < m; i++) {
cin >> hoge.at(i).first >> hoge.at(i).second;
fuga[hoge.at(i).first].push_back(hoge.at(i).second);
}
for (int a = 1; a <= n; a++) {
sort(fuga[a].begin(), fuga[a].end());
}
for (auto at : hoge) {
int a = at.first;
int b = at.second;
int fst = a;
int ed = 0;
int left = 0;
int right = fuga[a].size() - 1;
while (left <= right) {
int mid = (left + right) / 2;
if (fuga[a].at(mid) == b) {
ed = mid + 1;
break;
} else if (fuga[a].at(mid) > b) {
right = mid - 1;
} else {
left = mid + 1;
}
}
string mae = to_string(fst);
string usiro = to_string(ed);
while (mae.size() < 6) {
mae = "0" + mae;
}
while (usiro.size() < 6) {
usiro = "0" + usiro;
}
cout << mae + usiro << endl;
}
return 0;
} | replace | 17 | 19 | 17 | 19 | TLE | |
p03221 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
int n, m;
cin >> n >> m;
vector<vector<int>> vec(100010, vector<int>());
vector<P> ve(m);
rep(i, m) {
int p, y;
scanf("%d%d", &p, &y);
ve[i].first = p;
ve[i].second = y;
vec[p].push_back(y);
}
rep(i, 100010) sort(vec[i].begin(), vec[i].end());
rep(i, m) {
int e;
rep(j, vec[ve[i].first].size()) {
if (vec[ve[i].first][j] == ve[i].second) {
e = j;
break;
}
}
printf("%06d", ve[i].first);
printf("%06d\n", e + 1);
}
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
int n, m;
cin >> n >> m;
vector<vector<int>> vec(100010, vector<int>());
vector<P> ve(m);
rep(i, m) {
int p, y;
scanf("%d%d", &p, &y);
ve[i].first = p;
ve[i].second = y;
vec[p].push_back(y);
}
rep(i, 100010) sort(vec[i].begin(), vec[i].end());
rep(i, m) printf("%012lld\n",
ll(ve[i].first) * 1000000 +
int(lower_bound(vec[ve[i].first].begin(),
vec[ve[i].first].end(), ve[i].second) -
vec[ve[i].first].begin()) +
1);
return 0;
} | replace | 19 | 30 | 19 | 25 | TLE | |
p03221 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>
using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000007;
struct city {
Int pref; // 県番号
Int year;
Int num; // 県の内何番目か
Int id; // 入力番号
};
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
Int N, M;
cin >> N >> M;
vector<city> cities(M);
for (Int i = 0; i < M; i++) {
cin >> cities[i].pref >> cities[i].year;
cities[i].id = i;
}
// yearでsort
sort(cities.begin(), cities.end(),
[](const city &x, const city &y) { return x.year < y.year; });
vector<Int> Pre(M + 1);
for (Int i = 0; i < M; i++) {
Pre[cities[i].pref]++;
cities[i].num = Pre[cities[i].pref];
}
// idでsort
sort(cities.begin(), cities.end(),
[](const city &x, const city &y) { return x.id < y.id; });
for (Int i = 0; i < M; i++) {
printf("%06lld", cities[i].pref);
printf("%06lld\n", cities[i].num);
}
} | #include <algorithm>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>
using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000007;
struct city {
Int pref; // 県番号
Int year;
Int num; // 県の内何番目か
Int id; // 入力番号
};
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
Int N, M;
cin >> N >> M;
vector<city> cities(M);
for (Int i = 0; i < M; i++) {
cin >> cities[i].pref >> cities[i].year;
cities[i].id = i;
}
// yearでsort
sort(cities.begin(), cities.end(),
[](const city &x, const city &y) { return x.year < y.year; });
vector<Int> Pre(100001);
for (Int i = 0; i < M; i++) {
Pre[cities[i].pref]++;
cities[i].num = Pre[cities[i].pref];
}
// idでsort
sort(cities.begin(), cities.end(),
[](const city &x, const city &y) { return x.id < y.id; });
for (Int i = 0; i < M; i++) {
printf("%06lld", cities[i].pref);
printf("%06lld\n", cities[i].num);
}
} | replace | 42 | 43 | 42 | 43 | 0 | |
p03221 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<int, int> P;
int main() {
int n, m;
cin >> n >> m;
vector<int> order[n];
vector<pair<int, int>> city(m);
for (int i = 0; i < m; i++) {
cin >> city[i].first >> city[i].second;
order[city[i].first - 1].push_back(city[i].second);
}
for (int i = 0; i < n; i++) {
sort(order[i].begin(), order[i].end());
}
for (int i = 0; i < m; i++) {
int prefercture = city[i].first - 1;
int birth;
for (int j = 0; j < order[prefercture].size(); ++j) {
if (order[prefercture][j] == city[i].second) {
birth = j + 1;
break;
}
}
printf("%06d%06d\n", prefercture + 1, birth);
// cout << prefercture+1 << " " << birth << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<int, int> P;
int main() {
int n, m;
cin >> n >> m;
vector<int> order[n];
vector<pair<int, int>> city(m);
for (int i = 0; i < m; i++) {
cin >> city[i].first >> city[i].second;
order[city[i].first - 1].push_back(city[i].second);
}
for (int i = 0; i < n; i++) {
sort(order[i].begin(), order[i].end());
}
for (int i = 0; i < m; i++) {
int prefercture = city[i].first - 1;
auto birthIter = lower_bound(order[prefercture].begin(),
order[prefercture].end(), city[i].second);
int birth = birthIter - order[prefercture].begin() + 1;
printf("%06d%06d\n", prefercture + 1, birth);
// cout << prefercture+1 << " " << birth << endl;
}
return 0;
}
| replace | 35 | 42 | 35 | 38 | TLE | |
p03221 | C++ | Runtime Error | #include "bits/stdc++.h"
using namespace std;
#define sp(x) cout << setprecision(x);
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX * 0.99
typedef long long ll;
typedef pair<int, int> P;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m; // n=prefecture m=city
vector<vector<P>> v(m);
REP(i, m) {
int p, y; //
cin >> p >> y;
P temp;
p--;
temp.first = y;
temp.second = i;
v[p].push_back(temp);
// v[i].push_back(P(p,y));
}
vector<P> ans(m);
REP(i, n) {
sort(all(v[i]));
// v[i][j] := i個目の県の中でj番目に速く誕生した市の誕生した年と市の番号
REP(j, v[i].size()) { ans[v[i][j].second] = P(i + 1, j + 1); }
}
REP(i, m) { printf("%06d%06d\n", ans[i].first, ans[i].second); }
} | #include "bits/stdc++.h"
using namespace std;
#define sp(x) cout << setprecision(x);
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX * 0.99
typedef long long ll;
typedef pair<int, int> P;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m; // n=prefecture m=city
vector<vector<P>> v(n);
REP(i, m) {
int p, y; //
cin >> p >> y;
P temp;
p--;
temp.first = y;
temp.second = i;
v[p].push_back(temp);
// v[i].push_back(P(p,y));
}
vector<P> ans(m);
REP(i, n) {
sort(all(v[i]));
// v[i][j] := i個目の県の中でj番目に速く誕生した市の誕生した年と市の番号
REP(j, v[i].size()) { ans[v[i][j].second] = P(i + 1, j + 1); }
}
REP(i, m) { printf("%06d%06d\n", ans[i].first, ans[i].second); }
} | replace | 19 | 20 | 19 | 20 | 0 | |
p03221 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
int main() {
long N, M;
vector<vector<long long>> P;
cin >> N >> M;
P = vector<vector<long long>>(N, vector<long long>(0, 0));
long long p[M], y[M];
for (long i = 0; i < M; i++) {
scanf("%lld %lld", &p[i], &y[i]);
P[--p[i]].push_back(y[i]);
}
for (long i = 0; i < N; i++) {
if (P[i].size() != 0)
sort(P[i].begin(), P[i].end());
}
for (long i = 0; i < M; i++) {
auto itr = find(P[p[i]].begin(), P[p[i]].end(), y[i]);
long idx = distance(P[p[i]].begin(), itr);
printf("%06lld%06ld\n", p[i] + 1, idx + 1);
}
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
int main() {
long N, M;
vector<vector<long long>> P;
cin >> N >> M;
P = vector<vector<long long>>(N, vector<long long>(0, 0));
long long p[M], y[M];
for (long i = 0; i < M; i++) {
scanf("%lld %lld", &p[i], &y[i]);
P[--p[i]].push_back(y[i]);
}
for (long i = 0; i < N; i++) {
if (P[i].size() != 0)
sort(P[i].begin(), P[i].end());
}
for (long i = 0; i < M; i++) {
auto itr = lower_bound(P[p[i]].begin(), P[p[i]].end(), y[i]);
long idx = distance(P[p[i]].begin(), itr);
printf("%06lld%06ld\n", p[i] + 1, idx + 1);
}
return 0;
}
| replace | 44 | 45 | 44 | 45 | TLE | |
p03221 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <cmath>
const double PI = 3.14159265358979323846;
// using namespace boost::multiprecision;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 1e15;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;
std::istream &operator>>(std::istream &in, set<int> &o) {
ll a;
in >> a;
o.insert(a);
return in;
}
std::istream &operator>>(std::istream &in, queue<int> &o) {
ll a;
in >> a;
o.push(a);
return in;
}
bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }
// ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
// ofstream outfile("log.txt");
// outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0')
// << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
// const ll mod = 1e10;
typedef priority_queue<string, vector<string>, greater<string>> PQ_ASK;
struct City {
ll id, prefecture, year, rank;
};
int main() {
int n, m;
cin >> n >> m;
vector<City> cities(m);
rep(i, m) cities[i].id = i;
rep(i, m) cin >> cities[i].prefecture >> cities[i].year;
sort(cities.begin(), cities.end(), [](City &c, City &d) {
if (c.prefecture != d.prefecture)
return c.prefecture < d.prefecture;
return c.year < d.year;
});
cities[0].rank = 0;
for (int i = 1; i < n; i++) {
if (cities[i - 1].prefecture != cities[i].prefecture) {
cities[i].rank = 0;
} else {
cities[i].rank = cities[i - 1].rank + 1;
}
}
sort(cities.begin(), cities.end(),
[](City &c, City &d) { return c.id < d.id; });
for (City &c : cities) {
printf("%06lld%06lld\n", c.prefecture, c.rank + 1);
}
} | #include <bits/stdc++.h>
#include <cmath>
const double PI = 3.14159265358979323846;
// using namespace boost::multiprecision;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 1e15;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;
std::istream &operator>>(std::istream &in, set<int> &o) {
ll a;
in >> a;
o.insert(a);
return in;
}
std::istream &operator>>(std::istream &in, queue<int> &o) {
ll a;
in >> a;
o.push(a);
return in;
}
bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }
// ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
// ofstream outfile("log.txt");
// outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0')
// << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
// const ll mod = 1e10;
typedef priority_queue<string, vector<string>, greater<string>> PQ_ASK;
struct City {
ll id, prefecture, year, rank;
};
int main() {
int n, m;
cin >> n >> m;
vector<City> cities(m);
rep(i, m) cities[i].id = i;
rep(i, m) cin >> cities[i].prefecture >> cities[i].year;
sort(cities.begin(), cities.end(), [](City &c, City &d) {
if (c.prefecture != d.prefecture)
return c.prefecture < d.prefecture;
return c.year < d.year;
});
cities[0].rank = 0;
for (int i = 1; i < m; i++) {
if (cities[i - 1].prefecture != cities[i].prefecture) {
cities[i].rank = 0;
} else {
cities[i].rank = cities[i - 1].rank + 1;
}
}
sort(cities.begin(), cities.end(),
[](City &c, City &d) { return c.id < d.id; });
for (City &c : cities) {
printf("%06lld%06lld\n", c.prefecture, c.rank + 1);
}
} | replace | 57 | 58 | 57 | 58 | 0 | |
p03221 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int inum(int N, int W) { return N / W; }
int jnum(int N, int W) {
if ((N / W) % 2)
return N % W;
else
return W - (N % W) - 1;
}
int main() {
int n, m;
cin >> n >> m;
vector<int> P(n), Y(n);
vector<vector<int>> yd(n + 1);
rep(i, m) {
cin >> P[i] >> Y[i];
yd[P[i]].push_back(Y[i]);
}
rep(i, n) sort(yd[i + 1].begin(), yd[i + 1].end());
rep(i, m) cout << setw(12) << setfill('0')
<< ll(P[i]) * 1000000 + int(lower_bound(yd[P[i]].begin(),
yd[P[i]].end(), Y[i]) -
yd[P[i]].begin() + 1)
<< endl;
}
| #include <bits/stdc++.h>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int inum(int N, int W) { return N / W; }
int jnum(int N, int W) {
if ((N / W) % 2)
return N % W;
else
return W - (N % W) - 1;
}
int main() {
int n, m;
cin >> n >> m;
vector<int> P(m), Y(m);
vector<vector<int>> yd(n + 1);
rep(i, m) {
cin >> P[i] >> Y[i];
yd[P[i]].push_back(Y[i]);
}
rep(i, n) sort(yd[i + 1].begin(), yd[i + 1].end());
rep(i, m) cout << setw(12) << setfill('0')
<< ll(P[i]) * 1000000 + int(lower_bound(yd[P[i]].begin(),
yd[P[i]].end(), Y[i]) -
yd[P[i]].begin() + 1)
<< endl;
}
| replace | 19 | 20 | 19 | 20 | 0 | |
p03221 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, M;
scanf("%d%d", &N, &M);
vector<tuple<int, int, int>> pref_year_id(M);
for (int i = 0; i < M; i++) {
int pid, year;
scanf("%d%d", &pid, &year);
pref_year_id.at(i) = make_tuple(pid, year, i);
}
sort(pref_year_id.begin(), pref_year_id.end());
vector<int> pref_id(M), city_id(M), cnt(M + 1);
for (auto pyi : pref_year_id) {
int pid, id;
tie(pid, ignore, id) = pyi;
pref_id.at(id) = pid;
cnt[pid]++;
city_id.at(id) = cnt[pid];
}
for (int i = 0; i < M; i++) {
cout << setfill('0') << setw(6) << pref_id.at(i);
cout << setfill('0') << setw(6) << city_id.at(i) << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int N, M;
scanf("%d%d", &N, &M);
vector<tuple<int, int, int>> pref_year_id(M);
for (int i = 0; i < M; i++) {
int pid, year;
scanf("%d%d", &pid, &year);
pref_year_id.at(i) = make_tuple(pid, year, i);
}
sort(pref_year_id.begin(), pref_year_id.end());
vector<int> pref_id(M), city_id(M), cnt(N + 1);
for (auto &pyi : pref_year_id) {
int pid, id;
tie(pid, ignore, id) = pyi;
pref_id.at(id) = pid;
cnt[pid]++;
city_id.at(id) = cnt[pid];
}
for (int i = 0; i < M; i++) {
cout << setfill('0') << setw(6) << pref_id.at(i);
cout << setfill('0') << setw(6) << city_id.at(i) << endl;
}
return 0;
}
| replace | 16 | 18 | 16 | 18 | 0 | |
p03221 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
struct city {
int id1;
int id2;
int year;
int num;
};
city cities[10002];
bool cmp1(city a, city b) {
if (a.id1 != b.id1) {
return a.id1 < b.id1;
} else {
return a.year < b.year;
}
}
bool cmp2(city a, city b) { return a.num < b.num; }
void add0(int a) {
if (a < 10) {
cout << "00000";
} else if (a < 100) {
cout << "0000";
} else if (a < 1000) {
cout << "000";
} else if (a < 10000) {
cout << "00";
} else if (a < 100000) {
cout << "0";
}
cout << a;
}
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> cities[i].id1 >> cities[i].year;
cities[i].num = i;
}
sort(cities, cities + m, cmp1);
int t1 = 0;
cities[0].id2 = 1;
for (int i = 1; i < m; i++) {
if (cities[i].id1 != cities[i - 1].id1) {
cities[i].id2 = 1;
} else {
cities[i].id2 = cities[i - 1].id2 + 1;
}
}
sort(cities, cities + m, cmp2);
for (int i = 0; i < m; i++) {
add0(cities[i].id1);
add0(cities[i].id2);
cout << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
struct city {
int id1;
int id2;
int year;
int num;
};
city cities[100002];
bool cmp1(city a, city b) {
if (a.id1 != b.id1) {
return a.id1 < b.id1;
} else {
return a.year < b.year;
}
}
bool cmp2(city a, city b) { return a.num < b.num; }
void add0(int a) {
if (a < 10) {
cout << "00000";
} else if (a < 100) {
cout << "0000";
} else if (a < 1000) {
cout << "000";
} else if (a < 10000) {
cout << "00";
} else if (a < 100000) {
cout << "0";
}
cout << a;
}
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> cities[i].id1 >> cities[i].year;
cities[i].num = i;
}
sort(cities, cities + m, cmp1);
int t1 = 0;
cities[0].id2 = 1;
for (int i = 1; i < m; i++) {
if (cities[i].id1 != cities[i - 1].id1) {
cities[i].id2 = 1;
} else {
cities[i].id2 = cities[i - 1].id2 + 1;
}
}
sort(cities, cities + m, cmp2);
for (int i = 0; i < m; i++) {
add0(cities[i].id1);
add0(cities[i].id2);
cout << endl;
}
return 0;
} | replace | 8 | 9 | 8 | 9 | 0 | |
p03221 | C++ | Runtime Error | #include <algorithm>
#include <stdio.h>
int main(void) {
int n, m;
scanf("%lld%lld", &n, &m);
unsigned long long p[m], y[m];
unsigned long long x[m];
for (int i = 0; i < m; i++) {
scanf("%lu%lu", &p[i], &y[i]);
x[i] = (p[i] << 47) + (y[i] << 17) + i;
}
std::sort(x, x + m);
int c = 1;
y[(x[0] << 47) >> 47] = c;
for (int i = 1; i < m; i++) {
if (x[i] >> 47 == x[i - 1] >> 47)
c++;
else
c = 1;
y[(x[i] << 47) >> 47] = c;
}
for (int i = 0; i < m; i++) {
printf("%06lu%06lu\n", p[i], y[i]);
}
} | #include <algorithm>
#include <stdio.h>
int main(void) {
int n, m;
scanf("%d%d", &n, &m);
unsigned long long p[m], y[m];
unsigned long long x[m];
for (int i = 0; i < m; i++) {
scanf("%lu%lu", &p[i], &y[i]);
x[i] = (p[i] << 47) + (y[i] << 17) + i;
}
std::sort(x, x + m);
int c = 1;
y[(x[0] << 47) >> 47] = c;
for (int i = 1; i < m; i++) {
if (x[i] >> 47 == x[i - 1] >> 47)
c++;
else
c = 1;
y[(x[i] << 47) >> 47] = c;
}
for (int i = 0; i < m; i++) {
printf("%06lu%06lu\n", p[i], y[i]);
}
} | replace | 4 | 5 | 4 | 5 | 0 | |
p03221 | C++ | Runtime Error | #include <algorithm>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
// #define INF 100000000
// #define MOD (int) (1e9+7)
#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;
const int MAX = 1000000;
const int MOD = 998244353;
int main() {
int n, m;
cin >> n >> m;
vector<int> p(n), y(m);
int i;
for (i = 0; i < m; i++) {
cin >> p[i] >> y[i];
p[i]--;
}
vector<vector<int>> v(n);
for (i = 0; i < m; i++) {
v[p[i]].push_back(y[i]);
}
for (i = 0; i < n; i++) {
// ソートする
sort(v[i].begin(), v[i].end());
// ダブりを消す
v[i].erase(unique(v[i].begin(), v[i].end()), v[i].end());
}
for (i = 0; i < m; i++) {
printf("%06d", p[i] + 1);
// 座圧との対応付け
int id =
lower_bound(v[p[i]].begin(), v[p[i]].end(), y[i]) - v[p[i]].begin();
printf("%06d\n", id + 1);
}
} | #include <algorithm>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
// #define INF 100000000
// #define MOD (int) (1e9+7)
#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;
const int MAX = 1000000;
const int MOD = 998244353;
int main() {
int n, m;
cin >> n >> m;
vector<int> p(m), y(m);
int i;
for (i = 0; i < m; i++) {
cin >> p[i] >> y[i];
p[i]--;
}
vector<vector<int>> v(n);
for (i = 0; i < m; i++) {
v[p[i]].push_back(y[i]);
}
for (i = 0; i < n; i++) {
// ソートする
sort(v[i].begin(), v[i].end());
// ダブりを消す
v[i].erase(unique(v[i].begin(), v[i].end()), v[i].end());
}
for (i = 0; i < m; i++) {
printf("%06d", p[i] + 1);
// 座圧との対応付け
int id =
lower_bound(v[p[i]].begin(), v[p[i]].end(), y[i]) - v[p[i]].begin();
printf("%06d\n", id + 1);
}
} | replace | 22 | 23 | 22 | 23 | 0 | |
p03221 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
vector<pair<int, int>> p(M);
for (int i = 0; i < M; i++) {
int P, Y;
cin >> P >> Y;
P--;
p.at(i) = make_pair(Y, P);
}
vector<vector<int>> vals(N);
for (int i = 0; i < M; i++)
vals.at(p.at(i).second).push_back(p.at(i).first);
for (int v = 0; v < N; v++) {
sort(vals.at(v).begin(), vals.at(v).end());
}
for (int i = 0; i < M; ++i) {
int v = p.at(i).second;
printf("%06d", v + 1);
int id = lower_bound(vals.at(v).begin(), vals.at(v).end(), p.at(v).first) -
vals.at(v).begin();
printf("%06d\n", id + 1);
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
vector<pair<int, int>> p(M);
for (int i = 0; i < M; i++) {
int P, Y;
cin >> P >> Y;
P--;
p.at(i) = make_pair(Y, P);
}
vector<vector<int>> vals(N);
for (int i = 0; i < M; i++)
vals.at(p.at(i).second).push_back(p.at(i).first);
for (int v = 0; v < N; v++) {
sort(vals.at(v).begin(), vals.at(v).end());
}
for (int i = 0; i < M; ++i) {
int v = p.at(i).second;
printf("%06d", v + 1);
int id = lower_bound(vals.at(v).begin(), vals.at(v).end(), p.at(i).first) -
vals.at(v).begin();
printf("%06d\n", id + 1);
}
} | replace | 26 | 27 | 26 | 27 | 0 | |
p03221 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
using namespace std;
struct city {
int p;
int y;
int bian1;
int bian2;
} c[10005];
bool cmp1(city a, city b) {
if (a.p != b.p) {
return a.p < b.p;
} else {
return a.y < b.y;
}
}
bool cmp2(city a, city b) { return a.bian1 < b.bian1; }
int main() {
int n, m, i, x, s = 0, j = 0, z, t = 0, k;
cin >> n >> m;
for (i = 1; i <= m; i++) {
cin >> c[i].p >> c[i].y;
c[i].bian1 = i;
}
sort(c + 1, c + m + 1, cmp1);
int y = c[1].p;
for (i = 1; i <= m; i++) {
if (c[i].p == y) {
j++;
c[i].bian2 = j;
} else {
j = 1;
y = c[i].p;
c[i].bian2 = j;
}
}
sort(c + 1, c + m + 1, cmp2);
/*
////////////begin
for(i=1;i<=m;i++)
{
cout<<c[i].p<<' '<<c[i].y<<' '<<c[i].bian1<<' '<<c[i].bian2<<endl;
}
////////////end
*/
for (i = 1; i <= m; i++) {
x = c[i].p;
while (x != 0) {
x = x / 10;
s++;
}
for (k = 1; k <= 6 - s; k++) {
cout << '0';
}
cout << c[i].p;
s = 0;
z = c[i].bian2;
while (z != 0) {
z = z / 10;
t++;
}
for (k = 1; k <= 6 - t; k++) {
cout << '0';
}
cout << c[i].bian2 << endl;
t = 0;
}
return 0;
} | #include <algorithm>
#include <iostream>
using namespace std;
struct city {
int p;
int y;
int bian1;
int bian2;
} c[100005];
bool cmp1(city a, city b) {
if (a.p != b.p) {
return a.p < b.p;
} else {
return a.y < b.y;
}
}
bool cmp2(city a, city b) { return a.bian1 < b.bian1; }
int main() {
int n, m, i, x, s = 0, j = 0, z, t = 0, k;
cin >> n >> m;
for (i = 1; i <= m; i++) {
cin >> c[i].p >> c[i].y;
c[i].bian1 = i;
}
sort(c + 1, c + m + 1, cmp1);
int y = c[1].p;
for (i = 1; i <= m; i++) {
if (c[i].p == y) {
j++;
c[i].bian2 = j;
} else {
j = 1;
y = c[i].p;
c[i].bian2 = j;
}
}
sort(c + 1, c + m + 1, cmp2);
/*
////////////begin
for(i=1;i<=m;i++)
{
cout<<c[i].p<<' '<<c[i].y<<' '<<c[i].bian1<<' '<<c[i].bian2<<endl;
}
////////////end
*/
for (i = 1; i <= m; i++) {
x = c[i].p;
while (x != 0) {
x = x / 10;
s++;
}
for (k = 1; k <= 6 - s; k++) {
cout << '0';
}
cout << c[i].p;
s = 0;
z = c[i].bian2;
while (z != 0) {
z = z / 10;
t++;
}
for (k = 1; k <= 6 - t; k++) {
cout << '0';
}
cout << c[i].bian2 << endl;
t = 0;
}
return 0;
} | replace | 8 | 9 | 8 | 9 | 0 | |
p03221 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<int> p(m);
vector<int> y(m);
vector<int> py[100001];
for (int i = 0; i < m; i++) {
cin >> p[i] >> y[i];
py[p[i]].push_back(y[i]);
}
for (int i = 0; i < m; i++) {
sort(py[p[i]].begin(), py[p[i]].end());
}
for (int i = 0; i < m; i++) {
printf("%06d%06d\n", p[i],
(lower_bound(py[p[i]].begin(), py[p[i]].end(), y[i])) -
py[p[i]].begin() + 1);
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<int> p(m);
vector<int> y(m);
vector<int> py[100001];
for (int i = 0; i < m; i++) {
cin >> p[i] >> y[i];
py[p[i]].push_back(y[i]);
}
for (int i = 0; i < n; i++) {
sort(py[i + 1].begin(), py[i + 1].end());
}
for (int i = 0; i < m; i++) {
printf("%06d%06d\n", p[i],
(lower_bound(py[p[i]].begin(), py[p[i]].end(), y[i])) -
py[p[i]].begin() + 1);
}
return 0;
}
| replace | 12 | 14 | 12 | 14 | TLE | |
p03221 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <stdio.h>
using namespace std;
int answer[100005], preI[100005];
int main() {
int n, m, an, pr;
cin >> n >> m;
pair<int, pair<int, int>> v[n + 10];
for (int i = 0; i < m; i++) {
cin >> pr >> an;
v[i].second.first = an;
v[i].first = pr;
v[i].second.second = i;
}
sort(v, v + m);
int indx = 1;
for (int i = 0; i < m; i++) {
if (i > 0 && v[i].first != v[i - 1].first) {
indx = 1;
}
answer[v[i].second.second] = indx;
preI[v[i].second.second] = v[i].first;
indx++;
}
for (int i = 0; i < m; i++) {
printf("%06d", preI[i]);
printf("%06d\n", answer[i]);
}
return 0;
}
| #include <algorithm>
#include <iostream>
#include <stdio.h>
using namespace std;
int answer[100005], preI[100005];
int main() {
int n, m, an, pr;
cin >> n >> m;
pair<int, pair<int, int>> v[m + 10];
for (int i = 0; i < m; i++) {
cin >> pr >> an;
v[i].second.first = an;
v[i].first = pr;
v[i].second.second = i;
}
sort(v, v + m);
int indx = 1;
for (int i = 0; i < m; i++) {
if (i > 0 && v[i].first != v[i - 1].first) {
indx = 1;
}
answer[v[i].second.second] = indx;
preI[v[i].second.second] = v[i].first;
indx++;
}
for (int i = 0; i < m; i++) {
printf("%06d", preI[i]);
printf("%06d\n", answer[i]);
}
return 0;
}
| replace | 10 | 11 | 10 | 11 | 0 | |
p03221 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef vector<llong> V;
#define _ \
cin.tie(0); \
ios::sync_with_stdio(false);
llong n, m;
llong y[100010], p[100010];
V yp[100010];
int main() {
_;
cin >> n >> m;
REP(i, m) {
llong yy, pp;
cin >> pp >> yy;
y[i] = yy;
p[i] = pp;
yp[pp - 1].push_back(yy);
}
REP(i, m) VSORT(yp[p[i] - 1]);
REP(i, m) {
int index = lower_bound(yp[p[i] - 1].begin(), yp[p[i] - 1].end(), y[i]) -
yp[p[i] - 1].begin() + 1;
printf("%06lld%06d\n", p[i], index);
}
return 0;
}
| #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef vector<llong> V;
#define _ \
cin.tie(0); \
ios::sync_with_stdio(false);
llong n, m;
llong y[100010], p[100010];
V yp[100010];
int main() {
_;
cin >> n >> m;
REP(i, m) {
llong yy, pp;
cin >> pp >> yy;
y[i] = yy;
p[i] = pp;
yp[pp - 1].push_back(yy);
}
REP(i, n) VSORT(yp[i]);
REP(i, m) {
int index = lower_bound(yp[p[i] - 1].begin(), yp[p[i] - 1].end(), y[i]) -
yp[p[i] - 1].begin() + 1;
printf("%06lld%06d\n", p[i], index);
}
return 0;
}
| replace | 35 | 37 | 35 | 36 | TLE | |
p03221 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void) {
int N, M;
cin >> N >> M;
vector<tuple<int, int, int>> cities(M);
vector<tuple<int, int>> cities_id(M);
for (int i = 0; i < M; i++) {
int P, Y;
cin >> P >> Y;
cities[i] = make_tuple(Y, P, i);
}
sort(cities.begin(), cities.end());
vector<int> cities_number(M, 0);
for (auto &city : cities) {
int P = get<1>(city);
int i = get<2>(city);
cities_number[P - 1]++;
cities_id[i] = make_tuple(P, cities_number[P - 1]);
}
for (auto &city_id : cities_id) {
cout << setfill('0') << right << setw(6) << get<0>(city_id);
cout << setfill('0') << right << setw(6) << get<1>(city_id) << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void) {
int N, M;
cin >> N >> M;
vector<tuple<int, int, int>> cities(M);
vector<tuple<int, int>> cities_id(M);
for (int i = 0; i < M; i++) {
int P, Y;
cin >> P >> Y;
cities[i] = make_tuple(Y, P, i);
}
sort(cities.begin(), cities.end());
vector<int> cities_number(N, 0);
for (auto &city : cities) {
int P = get<1>(city);
int i = get<2>(city);
cities_number[P - 1]++;
cities_id[i] = make_tuple(P, cities_number[P - 1]);
}
for (auto &city_id : cities_id) {
cout << setfill('0') << right << setw(6) << get<0>(city_id);
cout << setfill('0') << right << setw(6) << get<1>(city_id) << endl;
}
return 0;
}
| replace | 16 | 17 | 16 | 17 | 0 |
Subsets and Splits