結果
問題 | No.230 Splarraay スプラレェーイ |
ユーザー |
![]() |
提出日時 | 2015-06-19 23:01:19 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 121 ms / 5,000 ms |
コード長 | 2,533 bytes |
コンパイル時間 | 2,778 ms |
コンパイル使用メモリ | 101,460 KB |
実行使用メモリ | 11,776 KB |
最終ジャッジ日時 | 2024-07-07 04:12:13 |
合計ジャッジ時間 | 4,507 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:94:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 94 | scanf("%d", &n); | ~~~~~^~~~~~~~~~ main.cpp:96:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 96 | scanf("%d", &qq); | ~~~~~^~~~~~~~~~~ main.cpp:102:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 102 | scanf("%d", &ty); | ~~~~~^~~~~~~~~~~ main.cpp:105:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 105 | scanf("%d%d", &l, &r); | ~~~~~^~~~~~~~~~~~~~~~ main.cpp:119:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 119 | scanf("%d%d", &l, &r); | ~~~~~^~~~~~~~~~~~~~~~
ソースコード
#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<cctype>#include<cstdlib>#include<algorithm>#include<bitset>#include<vector>#include<list>#include<deque>#include<queue>#include<map>#include<set>#include<stack>#include<cmath>#include<sstream>#include<fstream>#include<iomanip>#include<ctime>#include<complex>#include<functional>#include<climits>#include<cassert>#include<iterator>#include<unordered_map>using namespace std;#define MAX 200002int n;int w;struct st{int sum = 0;int lazy = -1;int a = 0;int b = 0;};st seg[MAX * 4];void update(int a){if (seg[a].lazy != -1){if (seg[a].lazy == 0){seg[a].a = seg[a].sum;seg[a].b = 0;}else{seg[a].a = 0;seg[a].b = seg[a].sum;}seg[a * 2 + 1].lazy = seg[a].lazy;seg[a * 2 + 2].lazy = seg[a].lazy;seg[a].lazy = -1;}}inline void init(int b, int l, int r){seg[b].sum = r - l;if (l + 1 == r){return;}init(b * 2 + 1, l, (l + r) >> 1);init(b * 2 + 2, (l + r) >> 1, r);}inline void add(int b, int l, int r, int ll, int rr,int x){update(b);if (ll <= l&&r <= rr){seg[b].lazy = x;update(b);return;}if (r<=ll || rr <= l){return;}add(b * 2 + 1, l, (l + r) >> 1, ll, rr, x);add(b * 2 + 2, (l + r) >> 1, r, ll, rr, x);seg[b].a = seg[b * 2 + 1].a + seg[b * 2 + 2].a;seg[b].b = seg[b * 2 + 1].b + seg[b * 2 + 2].b;seg[b].lazy = -1;}inline pair<int, int> q(int b, int l, int r, int ll, int rr){update(b);if (r <= ll || rr <= l){return make_pair(0, 0);}if (ll <= l&&r <= rr){return make_pair(seg[b].a, seg[b].b);}pair<int, int> R;R = q(b * 2 + 1, l, (l + r) >> 1, ll, rr);pair<int, int> f = q(b * 2 + 2, (l + r) >> 1, r, ll, rr);R.first += f.first;R.second += f.second;return R;}int main(){scanf("%d", &n);int qq;scanf("%d", &qq);long long int ans = 0;long long int ans1 = 0;init(0, 0, n);while (qq--){int ty;scanf("%d", &ty);if (ty == 0){int l, r;scanf("%d%d", &l, &r);pair<int, int> k = q(0, 0, n, l, r + 1);if (k.first == k.second){continue;}if (k.first > k.second){ans += (long long int)(k.first);}else{ans1 += (long long int)(k.second);}continue;}int l, r;scanf("%d%d", &l, &r);if (ty == 1){add(0, 0, n, l, r + 1, 0);}else{add(0, 0, n, l, r + 1, 1);}}pair<int, int> k = q(0, 0, n, 0, n);ans += (long long int)(k.first);ans1 += (long long int)(k.second);printf("%lld %lld\n", ans, ans1);return 0;}