結果
| 問題 |
No.230 Splarraay スプラレェーイ
|
| コンテスト | |
| ユーザー |
Kmcode1
|
| 提出日時 | 2015-06-19 22:51:40 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,501 bytes |
| コンパイル時間 | 2,722 ms |
| コンパイル使用メモリ | 100,080 KB |
| 実行使用メモリ | 11,904 KB |
| 最終ジャッジ日時 | 2024-07-07 04:09:38 |
| 合計ジャッジ時間 | 3,686 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 4 WA * 13 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:92:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
92 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
main.cpp:94:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
94 | scanf("%d", &qq);
| ~~~~~^~~~~~~~~~~
main.cpp:100:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
100 | scanf("%d", &ty);
| ~~~~~^~~~~~~~~~~
main.cpp:103:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
103 | scanf("%d%d", &l, &r);
| ~~~~~^~~~~~~~~~~~~~~~
main.cpp:117:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
117 | 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 200002
int 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;
}
inline pair<int, int> q(int b, int l, int r, int ll, int rr){
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{
ans += (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;
}
Kmcode1