結果
問題 | No.259 セグメントフィッシング+ |
ユーザー |
![]() |
提出日時 | 2015-08-01 00:19:53 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,487 bytes |
コンパイル時間 | 949 ms |
コンパイル使用メモリ | 101,528 KB |
実行使用メモリ | 7,040 KB |
最終ジャッジ日時 | 2024-07-18 00:14:23 |
合計ジャッジ時間 | 3,278 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 WA * 1 |
other | AC * 1 WA * 22 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:102:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 102 | scanf("%d%d", &n, &q); | ~~~~~^~~~~~~~~~~~~~~~ main.cpp:105:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 105 | scanf("%s", buf); | ~~~~~^~~~~~~~~~~ main.cpp:107:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 107 | scanf("%d%d%d", &t, &y, &z); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~
ソースコード
#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_set>#include<unordered_map>using namespace std;#define MAX 200002int n;int q;char buf[3];pair<int, int> mo(long long int t, long long int ich,bool x){ //false left,true rightif (x == 0){int sa = n - 1 - ich;if (t <= sa){return make_pair(ich + t, x);}t -= sa;t %= (n * 2);if (t ==0){return make_pair(n-1, x);}if (t <= n){return make_pair(n - t, x ^ 1);}t -= n;return make_pair(t-1, x);}else{int sa = ich;if (t <= sa){return make_pair(ich - t, x);}t -= sa;t %= (n * 2);if (t == 0){return make_pair(0, x);}if (t <= n){return make_pair(t, x ^ 1);}t -= n;return make_pair(n - t-1, x);}}struct BIT{long long int bit[MAX];BIT(){for (int i = 0; i < MAX; i++){bit[i] = 0;}}void add(int i, long long int x){i++;while (i < MAX){bit[i] += x;i += i&-i;}}long long int sum(int i){long long int r = 0;i++;while (i){r += bit[i];i -= i&-i;}return r;}long long int q(int a, int b){if (a > b){swap(a, b);}return sum(b) - sum(a - 1);}};BIT B[2];void ins(int a, int b, int c){B[b].add(a, c);}int main(){scanf("%d%d", &n, &q);while (q--){pair<int, int> kari;scanf("%s", buf);int t, y, z;scanf("%d%d%d", &t, &y, &z);if (buf[0] == 'L'){kari = mo(t, y, false);ins(kari.first, kari.second, z);continue;}if (buf[0] == 'R'){kari = mo(t, y, true);ins(kari.first, kari.second, z);continue;}long long int ans = 0;t %= (n+2);z--;for (int i = 0; i < 2; i++){pair<int, int> kari = mo(t, y, i);pair<int, int> kari2 = mo(t, z, i);if (kari.first>kari2.first){swap(kari, kari2);}if (kari.second != kari2.second){int chu = 0;if (i == 0){chu = n-1;}ans += B[kari.second].q(kari.first,chu);ans += B[kari2.second].q(chu, kari2.first);}else{ans += B[kari.second].q(kari2.first, kari.first);}}printf("%lld\n", ans);}return 0;}