結果
問題 | No.259 セグメントフィッシング+ |
ユーザー |
![]() |
提出日時 | 2015-07-31 22:26:47 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 56 ms / 2,000 ms |
コード長 | 3,559 bytes |
コンパイル時間 | 741 ms |
コンパイル使用メモリ | 87,904 KB |
実行使用メモリ | 8,192 KB |
最終ジャッジ日時 | 2024-07-17 23:11:17 |
合計ジャッジ時間 | 4,141 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 23 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:99:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 99 | scanf("%d%d", &N, &Q); | ~~~~~^~~~~~~~~~~~~~~~ main.cpp:110:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 110 | scanf("%s%d%d%d", x, &t, &y, &z); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <string>#include <vector>#include <algorithm>#include <numeric>#include <set>#include <map>#include <queue>#include <iostream>#include <sstream>#include <cstdio>#include <cmath>#include <ctime>#include <cstring>#include <cctype>#include <cassert>#include <limits>#include <functional>#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))#if defined(_MSC_VER) || __cplusplus > 199711L#define aut(r,v) auto r = (v)#else#define aut(r,v) __typeof(v) r = (v)#endif#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)#define all(o) (o).begin(), (o).end()#define pb(x) push_back(x)#define mp(x,y) make_pair((x),(y))#define mset(m,v) memset(m,v,sizeof(m))#define INF 0x3f3f3f3f#define INFL 0x3f3f3f3f3f3f3f3fLLusing namespace std;typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii; typedef long long ll;template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }struct FenwickTree {typedef long long T;vector<T> v;void init(int n) { v.assign(n, 0); }void add(int i, T x) {for(; i < (int)v.size(); i |= i+1) v[i] += x;}T sum(int i) const { //[0, i)T r = 0;for(-- i; i >= 0; i = (i & (i+1)) - 1) r += v[i];return r;}T sum(int left, int right) const { //[left, right)return sum(right) - sum(left);}};//Rで時刻0に位置0で放たれたとすると、時刻iではint calc(int i, int M) {int j = i % M, N = M / 2;if(j < N)return j;elsereturn M - 1 - j;}long long ftsum(int L, int R, const FenwickTree &ft) {amax(L, 0);amin(R, (int)ft.v.size());if(L >= R) return 0;return L == 0 ? ft.sum(R) : ft.sum(L, R);}long long querysub(int j, int z, int N, int M, const FenwickTree &ft) {long long res1 = 0, res2 = 0;//sum k such that calc(j + k, M) < z//calc(j + k, M) < z// (j + k) % M < z if (j + k) % M < N// long long res1a = 0, res2a = 0;// rep(k, M) if((j + k) % M < N && (j + k) % M < z) res1a += ft.sum(k, k + 1);// rep(k, M) if((j + k) % M >= N && M - 1 - (j + k) % M < z) res2a += ft.sum(k, k + 1);//j + k < N <-> k < N - j//j + k < z: k < z - jres1 += ftsum(0, min(N - j, z - j), ft);//M <= j + k < M + N <-> M - j <= k < M + N - j//(j + k) % M < z: k < z + M - jres1 += ftsum(M - j, min(M + N - j, z + M - j), ft);// if(res1 != res1a) cerr << "err 1" << endl;//M - 1 - (j + k) % M < z if (j + k) % M >= N//N <= j + k < M <-> N - j <= k < M - j//M - 1 - (j + k) < z: M - j - z <= kres2 += ftsum(max(M - j - z, N - j), M - j, ft);//M + N <= j + k <-> M + N - j <= k//M - 1 - (j + k - M) < z: 2 * M - j - z <= kres2 += ftsum(max(2 * M - j - z, M + N - j), M, ft);// if(res2 != res2a) cerr << "err 2" << endl;return res1 + res2;}int main() {int N, Q;scanf("%d%d", &N, &Q);vector<int> pos[2];int M = N * 2;pos[0].resize(N, -1);pos[1].resize(N, -1);rep(i, M)pos[i >= N][calc(i, M)] = i;FenwickTree ft; ft.init(M);rep(ii, Q) {char x[2];int t, y, z;scanf("%s%d%d%d", x, &t, &y, &z);if(*x == 'L' || *x == 'R') {int p = pos[*x == 'L'][y];int q = (p + M - t % M) % M;ft.add(q, +z);// cerr << "q = " << q << endl;}else if(*x == 'C') {int j = t % M;long long ans = 0;ans += querysub(j, z, N, M, ft);ans -= querysub(j, y, N, M, ft);printf("%lld\n", ans);}}return 0;}