Contest Duration: ~ (local time) (90 minutes)

Submission #16548157

Source Code Expand

Copy
```#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
using VB = vector<bool>;
using VVB = vector<vector<bool>>;
using VVI = vector<VI>;
using VVL = vector<VL>;
using PII = std::pair<int, int>;
using VPII = std::vector<std::pair<int, int>>;
using PLL = std::pair<ll, ll>;
using VPLL = std::vector<std::pair<ll, ll>>;
using TI3 = std::tuple<int, int, int>;
using TI4 = std::tuple<int, int, int, int>;
using TL3 = std::tuple<ll, ll, ll>;
using TL4 = std::tuple<ll, ll, ll, ll>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define rep3(i, s, n, d) for (int i = (s); i < (int)(n); i += (d))
#define allpt(v) (v).begin(), (v).end()
#define allpt_c(v) (v).cbegin(), (v).cend()
#define allpt_r(v) (v).rbegin(), (v).rend()
#define allpt_cr(v) (v).crbegin(), (v).crend()

const int mod1 = 1e9 + 7, mod2 = 998244353, mod3 = 1e9 + 9;
const int mod = mod1;
const ll inf = 1e18;

const string wsp = " ";
const string tb = "\t";
const string rt = "\n";
const string alphabets = "abcdefghijklmnopqrstuvwxyz";

template <typename T>
void show1dvec(const vector<T> &v) {
if (v.size() == 0) return;
int n = v.size() - 1;
rep(i, n) cout << v[i] << wsp;
cout << v[n] << rt;
return;
}

template <typename T>
void show2dvec(const vector<vector<T>> &v) {
int n = v.size();
rep(i, n) show1dvec(v[i]);
}

template <typename T, typename S>
void show1dpair(const vector<pair<T, S>> &v) {
int n = v.size();
rep(i, n) cout << v[i].first << wsp << v[i].second << rt;
return;
}

template <typename T, typename S>
void pairzip(const vector<pair<T, S>> &v, vector<T> &t, vector<T> &s) {
int n = v.size();
rep(i, n) {
t.push_back(v[i].first);
s.push_back(v[i].second);
}
return;
}

template <typename T>
void maxvec(vector<T> &v) {
T s = v[0];
int n = v.size();
rep(i, n - 1) {
if (s > v[i + 1]) {
v[i + 1] = s;
}
s = v[i + 1];
}
}

template <typename T, typename S>
bool myfind(T t, S s) {
return find(t.cbegin(), t.cend(), s) != t.cend();
}

bool check(int y, int x, int h, int w) {
return 0 <= y && y < h && 0 <= x && x < w;
}

bool iskadomatsu(int a, int b, int c) {
return (a != b && b != c && c != a) &&
((a > b && b < c) || (a < b && b > c));
}

double euc_dist(PII a, PII b) {
return sqrt(pow(a.first - b.first, 2) + pow(a.second - b.second, 2));
}

VS split(string s, char c) {
VS ret;
string part;
s += c;
rep(i, s.length()) {
if (s[i] == c) {
if (part != "") ret.emplace_back(part);
part = "";
} else if (s[i] != c) {
part += s[i];
}
}
return ret;
}

template <typename T, typename S, typename R>
ll pow_mod(T p, S q, R mod = 1ll) {
ll ret = 1, r = p;
while (q) {
if (q % 2) ret *= r, ret %= mod;
r = (r * r) % mod, q /= 2;
}
return ret % mod;
}

template <typename T, typename S>
ll pow_no_mod(T p, S q) {
ll ret = 1, r = p;
while (q) {
if (q % 2) ret *= r;
r = (r * r), q /= 2;
}
return ret;
}

void make_frac_tables(VL &frac_list, VL &frac_inv_list) {
rep(i, frac_list.size() - 1) {
frac_list[i + 1] *= frac_list[i] * (i + 1);
frac_list[i + 1] %= mod;
frac_inv_list[i + 1] *= frac_inv_list[i] * pow_mod(i + 1, mod - 2, mod);
frac_inv_list[i + 1] %= mod;
}
}

pair<VL, VL> make_frac_tables(int n) {
VL frac_list(n + 1, 1), frac_inv_list(n + 1, 1);
rep(i, n) {
frac_list[i + 1] *= frac_list[i] * (i + 1);
frac_list[i + 1] %= mod;
frac_inv_list[i + 1] *= frac_inv_list[i] * pow_mod(i + 1, mod - 2, mod);
frac_inv_list[i + 1] %= mod;
}
return make_pair(frac_list, frac_inv_list);
}

// ll comb(int a, int b, const VL &frac_list, const VL &frac_inv_list) {
//     if (a < b) return 0;
//     if (b < 0) return 0;
//     ll ret = frac_list[a];
//     ret *= frac_inv_list[b];
//     ret %= mod;
//     ret *= frac_inv_list[a - b];
//     ret %= mod;
//     return ret;
// }

void djkstra(int n, int s, int t, const vector<set<int>> &connect) {
const int intm = 1e9;
vector<int> shortest(n, intm);
shortest[s] = 0;
vector<int> search = {s};
vector<int> new_search;
while (!search.empty()) {
for (auto i : search) {
for (auto j : connect[i]) {
if (shortest[j] > 1 + shortest[i]) {
shortest[j] = 1 + shortest[i];
new_search.emplace_back(j);
}
}
}
search.clear();
search = new_search;
new_search.clear();
// show1dvec(search);
// show1dvec(shortest);
}
if (shortest[t] == intm) shortest[t] = -1;
printf("%d\n", shortest[t]);
}

struct node {
int parent = -1;
ll weight = 0;
int subtree = 1;
VPII children;
VPII connect;
node(int n) {
parent = -1;
weight = 0;
subtree = 1;
children;
connect;
}
};

template <typename T>
void cum_2d(int n, int m, vector<vector<T>> &v) {
ll s;
rep(i, n) {
s = 0;
rep(j, m) {
s += v[i + 1][j + 1];
v[i + 1][j + 1] = s;
}
}
rep(j, m) {
s = 0;
rep(i, n) {
s += v[i + 1][j + 1];
v[i + 1][j + 1] = s;
}
}
}

template <typename T>
void query_1(int n, int m, vector<vector<vector<T>>> &cum_k, VVI &field) {
int y1, x1, y2, x2, c1, c2;
cin >> y1 >> x1 >> y2 >> x2;
if (field[y1 - 1][x1 - 1] == field[y2 - 1][x2 - 1]) {
return;
}
c1 = field[y1 - 1][x1 - 1];
c2 = field[y2 - 1][x2 - 1];
swap(field[y1 - 1][x1 - 1], field[y2 - 1][x2 - 1]);
// cout << y1 << x1 << y2 << x2 << c1 << c2 << rt;

if (x1 < x2) swap(x1, x2);
if (y1 < y2) swap(y1, y2);

if (x1 > x2) {
rep2(i, y1, n + 1) {
++cum_k[c1][i][x2];
--cum_k[c2][i][x2];
}
}
if (y1 > y2) {
rep2(j, x1, m + 1) {
++cum_k[c1][y2][j];
--cum_k[c2][y2][j];
}
}
// show2dvec(cum_k[c1]);
// cout << rt;
// show2dvec(cum_k[c2]);
// cout << rt;
}

template <typename T>
void query_2(int n, int m, vector<vector<vector<T>>> &cum_k, int k) {
int y1, x1, y2, x2, c{-1};
cin >> y1 >> x1 >> y2 >> x2;
--x1, --y1;
ll ans{0}, total;
rep(ki, k) {
total = cum_k[ki][y2][x2] - cum_k[ki][y1][x2] - cum_k[ki][y2][x1] +
cum_k[ki][y1][x1];
if (total >= ans) {
ans = total;
c = ki;
}
}
cout << c + 1 << wsp << ans << rt;
}

int main() {
cin.tie(0);
ios::sync_with_stdio(false);

#ifdef DEBUG
cout << "DEBUG MODE" << endl;
ifstream in("input.txt");  // for debug
cin.rdbuf(in.rdbuf());     // for debug
#endif

int n, m, k, a, b, q, op;
cin >> n >> m >> k;
VVI field(n, VI(m));
vector<VVL> cum_k(k, VVL(n + 1, VL(m + 1, 0)));
rep(i, n) rep(j, m) {
cin >> field[i][j];
--field[i][j];
cum_k[field[i][j]][i + 1][j + 1] += 1;
}
// show2dvec(field);
rep(ki, k) { cum_2d(n, m, cum_k[ki]); }
cin >> q;
rep(qi, q) {
cin >> op;
if (op == 1) {
query_1(n, m, cum_k, field);
} else {
query_2(n, m, cum_k, k);
}
}

// show2dvec(field);

return 0;
}
```

#### Submission Info

Submission Time 2020-09-07 02:46:01+0900 C - 宝探し 2 ASTR1104 C++ (GCC 9.2.1) 0 7944 Byte WA 940 ms 203784 KB

#### Compile Error

```./Main.cpp: In constructor ‘node::node(int)’:
./Main.cpp:202:9: warning: statement has no effect [-Wunused-value]
202 |         children;
|         ^~~~~~~~
./Main.cpp:203:9: warning: statement has no effect [-Wunused-value]
203 |         connect;
|         ^~~~~~~
./Main.cpp:198:14: warning: unused parameter ‘n’ [-Wunused-parameter]
198 |     node(int n) {
|          ~~~~^
./Main.cpp: In function ‘int main()’:
./Main.cpp:288:18: warning: unused variable ‘a’ [-Wunused-variable]
288 |     int n, m, k, a, b, q, op;
|                  ^
./Main.cpp:288:21: warning: unused variable ‘b’ [-Wunused-variable]
288 |     int n, m, k, a, b, q, op;
|                     ^
./Main.cpp: In instantiation of ‘void query_2(int, int, std::vector<std::vector<std::vector<_Tp> > >&, int) [with T = long long int]’:
./Main.cpp:305:35:   required from here
./Main.cpp:260:18: warning: unused parameter ‘n’ [-Wunused-parameter]
260 | void query_2(int n, int m, vector<vector<vector<T>>> &cum_k, int k) {
|              ~~~~^
./Main.cpp:260:25: warning: unused parameter ‘m’ [-Wunused-parameter]
260 | void query_2(int n, int m, vector<vector<vector<T>>> &cum_k, int k) {
|                     ~~~~^
```

#### Judge Result

Set Name All
Score / Max Score 0 / 100
Status
 AC × 1 WA × 18
Set Name Test Cases
All 00-sample-00, 00-sample-01, 10-random_small-00, 10-random_small-01, 10-random_small-02, 10-random_small-03, 10-random_small-04, 10-random_small-05, 10-random_small-06, 10-random_small-07, 10-random_small-08, 20-random_large-00, 20-random_large-01, 20-random_large-02, 20-random_large-03, 20-random_large-04, 30-max_query-00, 30-max_query-01, 30-max_query-02
Case Name Status Exec Time Memory
00-sample-00 7 ms 3608 KB
00-sample-01 4 ms 3548 KB
10-random_small-00 42 ms 3512 KB
10-random_small-01 8 ms 3572 KB
10-random_small-02 21 ms 3636 KB
10-random_small-03 10 ms 3728 KB
10-random_small-04 49 ms 3712 KB
10-random_small-05 84 ms 5608 KB
10-random_small-06 13 ms 3808 KB
10-random_small-07 35 ms 4248 KB
10-random_small-08 17 ms 11668 KB
20-random_large-00 937 ms 203732 KB
20-random_large-01 937 ms 203708 KB
20-random_large-02 940 ms 203744 KB
20-random_large-03 934 ms 203716 KB
20-random_large-04 930 ms 203772 KB
30-max_query-00 766 ms 203720 KB
30-max_query-01 770 ms 203784 KB
30-max_query-02 760 ms 203784 KB