Submission #18889469
Source Code Expand
Copy
// #define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
typedef long long int64;
typedef pair<int, int> ii;
#define SZ(x) (int)((x).size())
template <typename T> static constexpr T inf = numeric_limits<T>::max() / 2;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }
struct fast_ios {
fast_ios() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
};
} fast_ios_;
template<typename T, size_t N>
struct fenwick {
T c[N];
fenwick() {
fill(c + 1, c + N, 0);
}
void add(int x, T y) {
for (; x < N; x += x & -x) {
c[x] += y;
}
}
T query(int x) {
T ret = 0;
for (; x; x -= x & -x) {
ret += c[x];
}
return ret;
}
};
int main() {
int n, m, len;
cin >> n >> m >> len;
vector<int> R(n, m), D(m, n);
set<ii> forbid;
for (int i = 0; i < len; ++i) {
int x, y;
cin >> x >> y;
--x; --y;
R[x] = min(R[x], y);
D[y] = min(D[y], x);
forbid.insert({x, y});
}
int X = 0, Y = 0;
for (X = 1; X < n && !forbid.count({X, 0}); ++X);
for (Y = 1; Y < m && !forbid.count({0, Y}); ++Y);
int64 ret = 0;
trace(R, D);
for (int i = 0; i < X; ++i) ret += R[i];
for (int j = 0; j < Y; ++j) ret += D[j];
trace(ret, X, Y);
ret -= 1LL * X * Y;
trace(ret);
vector<ii> a;
for (auto& [x, y] : forbid) {
if (x < X && y < Y) {
a.push_back({x, y});
}
}
reverse(a.begin(), a.end());
trace(a, ret);
vector<int> col(Y, X);
for (int i = 0; i < SZ(a); ++i) {
if (i - 1 >= 0 && a[i - 1].first == a[i].first) {
ret += a[i - 1].second - a[i].second;
} else {
ret += Y - a[i].second;
}
ret += col[a[i].second] - a[i].first - 1;
col[a[i].second] = a[i].first;
}
const int N = 2e5 + 10;
fenwick<int, N> F;
reverse(a.begin(), a.end());
fill(col.begin(), col.end(), 0);
for (int i = 0; i < SZ(a); ++i) {
ret -= F.query(Y - a[i].second - 1);
trace(F.query(Y - a[i].second));
if (!col[a[i].second]) {
col[a[i].second] = 1;
F.add(Y - a[i].second, 1);
}
}
cout << ret << '\n';
return 0;
}
Submission Info
Submission Time |
|
Task |
F - Rook on Grid |
User |
cuiaoxiang |
Language |
C++ (Clang 10.0.0) |
Score |
0 |
Code Size |
4304 Byte |
Status |
WA |
Exec Time |
327 ms |
Memory |
16956 KB |
Compile Error
./Main.cpp:78:42: warning: unused variable 'inf' [-Wunused-const-variable]
template <typename T> static constexpr T inf = numeric_limits<T>::max() / 2;
^
./Main.cpp:79:11: warning: unused variable 'MOD' [-Wunused-const-variable]
const int MOD = 1e9 + 7;
^
2 warnings generated.
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
0 / 600 |
Status |
|
|
Set Name |
Test Cases |
Sample |
sample_01.txt, sample_02.txt, sample_03.txt |
All |
hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, sample_01.txt, sample_02.txt, sample_03.txt |
Case Name |
Status |
Exec Time |
Memory |
hand_01.txt |
AC |
19 ms |
5752 KB |
hand_02.txt |
AC |
5 ms |
5900 KB |
hand_03.txt |
AC |
3 ms |
4472 KB |
hand_04.txt |
AC |
3 ms |
4232 KB |
hand_05.txt |
AC |
2 ms |
3952 KB |
hand_06.txt |
AC |
2 ms |
3924 KB |
random_01.txt |
WA |
323 ms |
16956 KB |
random_02.txt |
WA |
326 ms |
14704 KB |
random_03.txt |
WA |
318 ms |
14868 KB |
random_04.txt |
WA |
327 ms |
16780 KB |
random_05.txt |
WA |
295 ms |
15648 KB |
random_06.txt |
WA |
310 ms |
15484 KB |
random_07.txt |
WA |
311 ms |
15396 KB |
random_08.txt |
AC |
9 ms |
5884 KB |
random_09.txt |
WA |
12 ms |
5900 KB |
random_10.txt |
AC |
9 ms |
5864 KB |
random_11.txt |
AC |
232 ms |
13328 KB |
random_12.txt |
AC |
237 ms |
13272 KB |
random_13.txt |
AC |
230 ms |
13172 KB |
random_14.txt |
AC |
235 ms |
13224 KB |
random_15.txt |
WA |
230 ms |
13324 KB |
random_16.txt |
AC |
233 ms |
13264 KB |
random_17.txt |
AC |
234 ms |
13212 KB |
random_18.txt |
WA |
4 ms |
4020 KB |
random_19.txt |
WA |
4 ms |
3888 KB |
random_20.txt |
WA |
3 ms |
3964 KB |
sample_01.txt |
AC |
2 ms |
3812 KB |
sample_02.txt |
AC |
2 ms |
3844 KB |
sample_03.txt |
AC |
9 ms |
6056 KB |