結果
問題 | No.151 セグメントフィッシング |
ユーザー | uwi |
提出日時 | 2015-02-12 23:46:35 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 181 ms / 5,000 ms |
コード長 | 2,984 bytes |
コンパイル時間 | 3,840 ms |
コンパイル使用メモリ | 80,340 KB |
実行使用メモリ | 53,064 KB |
最終ジャッジ日時 | 2024-06-23 19:25:07 |
合計ジャッジ時間 | 7,448 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 71 ms
51,228 KB |
testcase_01 | AC | 70 ms
51,128 KB |
testcase_02 | AC | 73 ms
50,964 KB |
testcase_03 | AC | 72 ms
50,888 KB |
testcase_04 | AC | 71 ms
51,120 KB |
testcase_05 | AC | 72 ms
50,960 KB |
testcase_06 | AC | 74 ms
51,112 KB |
testcase_07 | AC | 73 ms
51,100 KB |
testcase_08 | AC | 112 ms
52,480 KB |
testcase_09 | AC | 111 ms
52,420 KB |
testcase_10 | AC | 113 ms
52,344 KB |
testcase_11 | AC | 113 ms
52,444 KB |
testcase_12 | AC | 145 ms
52,556 KB |
testcase_13 | AC | 146 ms
52,688 KB |
testcase_14 | AC | 142 ms
52,496 KB |
testcase_15 | AC | 142 ms
52,588 KB |
testcase_16 | AC | 142 ms
52,568 KB |
testcase_17 | AC | 104 ms
52,148 KB |
testcase_18 | AC | 107 ms
52,248 KB |
testcase_19 | AC | 181 ms
52,772 KB |
testcase_20 | AC | 181 ms
53,064 KB |
testcase_21 | AC | 116 ms
52,380 KB |
testcase_22 | AC | 114 ms
52,436 KB |
testcase_23 | AC | 133 ms
52,624 KB |
ソースコード
package q3xx; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.InputMismatchException; public class Q383 { static InputStream is; static PrintWriter out; static String INPUT = ""; static void solve() { int n = ni(), Q = ni(); long[] ft = new long[2*n+1]; long all = 0; for(int i = 0;i < Q;i++){ char x = nc(); int y = ni(), z = ni(); if(x == 'R'){ int pos = (y-i)%(2*n); if(pos < 0)pos+=2*n; addFenwick(ft, pos, z); all += z; }else if(x == 'L'){ int pos = (n+(n-1-y)-i)%(2*n); if(pos < 0)pos+=2*n; addFenwick(ft, pos, z); all += z; }else if(x == 'C'){ long ret = 0; // R { int l = (y-i)%(2*n); if(l < 0)l+=2*n; int r = (z-1-i)%(2*n); if(r < 0)r+=2*n; if(l <= r){ ret += sumFenwick(ft, r) - sumFenwick(ft, l-1); }else{ ret += sumFenwick(ft, r) + all - sumFenwick(ft, l-1); } } // L { int l = (n+(n-1-(z-1))-i)%(2*n); if(l < 0)l+=2*n; int r = (n+(n-1-y)-i)%(2*n); if(r < 0)r+=2*n; if(l <= r){ ret += sumFenwick(ft, r) - sumFenwick(ft, l-1); }else{ ret += sumFenwick(ft, r) + all - sumFenwick(ft, l-1); } } out.println(ret); } } } public static long sumFenwick(long[] ft, int i) { long sum = 0; for(i++;i > 0;i -= i&-i)sum += ft[i]; return sum; } public static void addFenwick(long[] ft, int i, long v) { if(v == 0)return; int n = ft.length; for(i++;i < n;i += i&-i)ft[i] += v; } public static void main(String[] args) throws Exception { long S = System.currentTimeMillis(); is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes()); out = new PrintWriter(System.out); solve(); out.flush(); long G = System.currentTimeMillis(); tr(G-S+"ms"); } private static byte[] inbuf = new byte[1024]; static int lenbuf = 0, ptrbuf = 0; private static int readByte() { if(lenbuf == -1)throw new InputMismatchException(); if(ptrbuf >= lenbuf){ ptrbuf = 0; try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); } if(lenbuf <= 0)return -1; } return inbuf[ptrbuf++]; } private static boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } private static int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; } private static char nc() { return (char)skip(); } private static int ni() { int num = 0, b; boolean minus = false; while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')); if(b == '-'){ minus = true; b = readByte(); } while(true){ if(b >= '0' && b <= '9'){ num = num * 10 + (b - '0'); }else{ return minus ? -num : num; } b = readByte(); } } private static void tr(Object... o) { if(INPUT.length() != 0)System.out.println(Arrays.deepToString(o)); } }