結果
| 問題 |
No.1649 Manhattan Square
|
| コンテスト | |
| ユーザー |
rk427454171
|
| 提出日時 | 2021-08-13 23:09:05 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 325 ms / 3,000 ms |
| コード長 | 2,625 bytes |
| コンパイル時間 | 1,996 ms |
| コンパイル使用メモリ | 182,396 KB |
| 実行使用メモリ | 10,372 KB |
| 最終ジャッジ日時 | 2024-10-03 22:36:29 |
| 合計ジャッジ時間 | 14,705 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 43 |
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:62:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
62 | for(auto &[x, y] : arr)
| ^
main.cpp:66:25: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
66 | for(const auto &[x, y] : arr) {
| ^
ソースコード
/*
-------------- | /
| | /
| | /
| * |/ | | ------ *
| | | | / \
| | |\ | | | |\ |
\ | | | \ | | | | \ |
\ | | | \ | | \ / \ |
V | | \ \__/| ----- \ |
*/
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr << "\e[1;31m" << #x << " = " << (x) << "\e[0m\n"
#define print(x) emilia_mata_tenshi(#x, begin(x), end(x))
template<typename T> void emilia_mata_tenshi(const char *s, T l, T r) {
cerr << "\e[1;33m" << s << " = [";
while(l != r) {
cerr << *l;
cerr << (++l == r ? ']' : ',');
}
cerr << "\e[0m\n";
}
#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(NULL);
using ll = int64_t;
using ull = uint64_t;
using ld = long double;
using uint = uint32_t;
const double EPS = 1e-8;
const int INF = 0x3F3F3F3F;
const ll LINF = 4611686018427387903;
const int MOD = 1e9+7;
/*--------------------------------------------------------------------------------------*/
const int mod = 998244353, N = 2e5 + 25;
struct fenwicktree {
int arr[N];
void edt(int p, ll v) {
v %= mod;
for(; p < N; p += p & -p)
arr[p] = (arr[p] + v) % mod;
}
ll que(int l, int r) {
ll res = 0;
for(; r; r -= r & -r)
res = (res + arr[r]) % mod;
for(l--; l; l -= l & -l)
res = (res - arr[l] + mod) % mod;
return res;
}
} cnt, sum, sum2, rcnt, rsum, rsum2;
signed main() { EmiliaMyWife
int n;
cin >> n;
vector<pair<int, int>> arr(n);
vector<int> v(1, -10);
for(int i = 0; i < n; i++)
cin >> arr[i].first >> arr[i].second, v.push_back(arr[i].second);
sort(arr.begin(), arr.end());
sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end());
for(auto &[x, y] : arr)
y = lower_bound(v.begin(), v.end(), y) - v.begin();
ll ans = 0;
for(const auto &[x, y] : arr) {
ll t = (x + v[y]) % mod;
ans = (ans + t * t % mod * cnt.que(1, y) + sum.que(1, y)) % mod;
ans = (ans - 2 * t * sum2.que(1, y) % mod + mod) % mod;
cnt.edt(y, 1);
sum.edt(y, t * t % mod);
sum2.edt(y, t);
//debug(ans);
t = (x - v[y] + mod) % mod;
ans = (ans + t * t % mod * rcnt.que(y + 1, n) + rsum.que(y + 1, n)) % mod;
ans = (ans - 2 * t * rsum2.que(y + 1, n) % mod + mod) % mod;
rcnt.edt(y, 1);
rsum.edt(y, t * t % mod);
rsum2.edt(y, t);
//debug(ans);
}
cout << (ans + mod) % mod << '\n';
}
rk427454171