結果
| 問題 |
No.151 セグメントフィッシング
|
| コンテスト | |
| ユーザー |
omu
|
| 提出日時 | 2015-04-07 13:22:13 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,354 bytes |
| コンパイル時間 | 828 ms |
| コンパイル使用メモリ | 91,328 KB |
| 実行使用メモリ | 10,696 KB |
| 最終ジャッジ日時 | 2024-07-04 03:41:21 |
| 合計ジャッジ時間 | 2,285 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 18 WA * 1 |
ソースコード
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <list>
#include <iomanip>
#include <fstream>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
template<class T> inline T sqr(T x) { return x*x; }
typedef pair<int, int> P;
typedef long long ll;
typedef unsigned long long ull;
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define clr(a) memset((a), 0 ,sizeof(a))
#define mclr(a) memset((a), -1 ,sizeof(a))
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define sz(a) (sizeof(a))
#define Fill(a,v) fill((int*)a,(int*)(a+(sz(a)/sz(*(a)))),v)
bool cheak(int x, int y, int xMax, int yMax){ return x >= 0 && y >= 0 && xMax > x && yMax > y; }
const int dx[4] = { -1, 0, 1, 0 }, dy[4] = { 0, 1, 0, -1 };
const int mod = 1000000007;
const int INF = 2147483647;
struct BIT{
int n;
ll bit[1000010];
void init(int n){
n += 100000;
this->n = n;
for (int x = 1; x < n; ++x)bit[x + (x & -x)] += bit[x];
}
void add(int a, ll w){
a += 100000;
for (int x = a; x <= n; x += x & -x) bit[x] += w;
}
ll sum(int a){
a += 100000;
ll ret = 0;
for (int x = a; x > 0; x -= x & -x)ret += bit[x];
return ret;
}
};
BIT r, l;
int main()
{
int n , q;
cin >> n >> q;
r.init(n*3), l.init(n*3);
rep(t, q){
char x;
int y,z;
cin >> x >> y >> z;
if (x == 'L'){
l.add(y+1+t,z);
}else
if (x == 'R'){
r.add(y+1-t,z);
}
if(x == 'C'){
ll sum = r.sum(z-t)-r.sum(y-t)+l.sum(z+t)-l.sum(y+t);
if (z == n)sum += l.sum(n+1+t)-l.sum(n+t);
if (y+1== 1)sum += r.sum(0-t);
cout << sum << endl;
}
ll ls = l.sum(1 + t);
ll rs = r.sum(n - t) - r.sum(n - t - 1);
l.add(1 + t, -ls);
r.add(n - t, -rs);
l.add(n + t + 1, rs);
r.add(1 - t - 1, ls);
/*
for (int i = 1; i < n + 1; i++){
z = i; y = i - 1;
int sum = r.sum(z - t) - r.sum(y - t) + l.sum(z + t) - l.sum(y + t);
if (z == n)sum += l.sum(n + 1 + t) - l.sum(n + t);
if (y == 0)sum += r.sum(0 - t);
cout << i - 1 << " " << sum << endl;
}
*/
}
return 0;
}
omu