結果
問題 | No.469 区間加算と一致検索の問題 |
ユーザー | tanzaku |
提出日時 | 2016-12-19 00:14:17 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 599 ms / 5,000 ms |
コード長 | 6,990 bytes |
コンパイル時間 | 4,296 ms |
コンパイル使用メモリ | 90,200 KB |
実行使用メモリ | 126,720 KB |
最終ジャッジ日時 | 2024-06-01 10:51:05 |
合計ジャッジ時間 | 21,148 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 56 ms
50,356 KB |
testcase_01 | AC | 55 ms
50,416 KB |
testcase_02 | AC | 81 ms
58,000 KB |
testcase_03 | AC | 108 ms
39,324 KB |
testcase_04 | AC | 112 ms
39,660 KB |
testcase_05 | AC | 129 ms
40,276 KB |
testcase_06 | AC | 122 ms
40,244 KB |
testcase_07 | AC | 128 ms
40,440 KB |
testcase_08 | AC | 133 ms
40,600 KB |
testcase_09 | AC | 99 ms
39,604 KB |
testcase_10 | AC | 107 ms
39,904 KB |
testcase_11 | AC | 97 ms
39,600 KB |
testcase_12 | AC | 124 ms
40,120 KB |
testcase_13 | AC | 108 ms
39,864 KB |
testcase_14 | AC | 74 ms
38,532 KB |
testcase_15 | AC | 98 ms
39,180 KB |
testcase_16 | AC | 124 ms
40,624 KB |
testcase_17 | AC | 122 ms
40,344 KB |
testcase_18 | AC | 128 ms
40,380 KB |
testcase_19 | AC | 80 ms
38,276 KB |
testcase_20 | AC | 127 ms
40,488 KB |
testcase_21 | AC | 89 ms
39,216 KB |
testcase_22 | AC | 55 ms
37,220 KB |
testcase_23 | AC | 263 ms
46,020 KB |
testcase_24 | AC | 261 ms
46,720 KB |
testcase_25 | AC | 259 ms
46,676 KB |
testcase_26 | AC | 254 ms
46,100 KB |
testcase_27 | AC | 257 ms
46,296 KB |
testcase_28 | AC | 254 ms
46,144 KB |
testcase_29 | AC | 258 ms
46,144 KB |
testcase_30 | AC | 253 ms
46,864 KB |
testcase_31 | AC | 254 ms
46,604 KB |
testcase_32 | AC | 262 ms
47,012 KB |
testcase_33 | AC | 573 ms
117,260 KB |
testcase_34 | AC | 560 ms
126,720 KB |
testcase_35 | AC | 585 ms
126,664 KB |
testcase_36 | AC | 588 ms
126,572 KB |
testcase_37 | AC | 580 ms
126,456 KB |
testcase_38 | AC | 572 ms
126,112 KB |
testcase_39 | AC | 599 ms
126,412 KB |
testcase_40 | AC | 568 ms
126,192 KB |
testcase_41 | AC | 571 ms
126,232 KB |
testcase_42 | AC | 581 ms
126,232 KB |
testcase_43 | AC | 577 ms
126,120 KB |
testcase_44 | AC | 574 ms
126,188 KB |
testcase_45 | AC | 588 ms
126,136 KB |
testcase_46 | AC | 586 ms
126,196 KB |
testcase_47 | AC | 569 ms
126,344 KB |
testcase_48 | AC | 58 ms
50,140 KB |
testcase_49 | AC | 57 ms
50,172 KB |
testcase_50 | AC | 574 ms
126,356 KB |
testcase_51 | AC | 564 ms
126,076 KB |
ソースコード
import java.io.*; import java.math.*; import java.util.*; import static java.util.Arrays.*; public class _469 { private static final int mod = (int)1e9+7; final Random random = new Random(0); final IOFast io = new IOFast(); /// MAIN CODE public void run() throws IOException { // int TEST_CASE = Integer.parseInt(new String(io.nextLine()).trim()); int TEST_CASE = 1; while(TEST_CASE-- != 0) { int n = io.nextInt(); int q = io.nextInt(); Seg2 seg = new Seg2(n); TreeMap<Long, Integer> mp = new TreeMap<>(); mp.put(0L, 0); for (int i = 0; i < q; i++) { char c = io.nextChar(); if (c == '!') { int l = io.nextInt(); int r = io.nextInt(); int v = io.nextInt(); seg.update(l, r, v); if (!mp.containsKey(seg.get())) { mp.put(seg.get(), i + 1); } } else { io.out.println(mp.get(seg.get())); } } } } static class Seg2 { final int n; final long[] zob; final long[] hash; final long[] seg; public Seg2(final int n) { this.n = Integer.highestOneBit(n) << 1; zob = new long[this.n << 1]; seg = new long[this.n << 1]; hash = new long[this.n << 1]; Random random = new Random(); for (int i = 0; i < this.n; i++) { zob[i + this.n - 1] = random.nextLong(); } for (int i = this.n - 2; i >= 0; i--) { zob[i] = zob[2*i+1] + zob[2*i+2]; } } long get() { return hash[0]; } void update(int l, int r, int v) { update(l, r, v, 0, 0, n); } void update(int l, int r, int v, int k, int curL, int curR) { if(curR <= l || curL >= r) return; if(l <= curL && curR <= r) { seg[k] += v; hash[k] += v * zob[k]; return; } final int curM = (curL + curR) / 2; update(l, r, v, 2 * k + 1, curL, curM); update(l, r, v, 2 * k + 2, curM, curR); hash[k] = hash[2*k+1] + hash[2*k+2] + seg[k] * zob[k]; } } /// TEMPLATE static int gcd(int n, int r) { return r == 0 ? n : gcd(r, n%r); } static long gcd(long n, long r) { return r == 0 ? n : gcd(r, n%r); } static <T> void swap(T[] x, int i, int j) { T t = x[i]; x[i] = x[j]; x[j] = t; } static void swap(int[] x, int i, int j) { int t = x[i]; x[i] = x[j]; x[j] = t; } void printArrayLn(int[] xs) { for(int i = 0; i < xs.length; i++) io.out.print(xs[i] + (i==xs.length-1?"\n":" ")); } void printArrayLn(long[] xs) { for(int i = 0; i < xs.length; i++) io.out.print(xs[i] + (i==xs.length-1?"\n":" ")); } static void dump(Object... o) { System.err.println(Arrays.deepToString(o)); } void main() throws IOException { // IOFast.setFileIO("rle-size.in", "rle-size.out"); try { run(); } catch (EndOfFileRuntimeException e) { } io.out.flush(); } public static void main(String[] args) throws IOException { new _469().main(); } static class EndOfFileRuntimeException extends RuntimeException { private static final long serialVersionUID = -8565341110209207657L; } static public class IOFast { private InputStream in = System.in; private PrintWriter out = new PrintWriter(System.out); private static int pos, readLen; private static final byte[] buffer = new byte[1024 * 8]; private static char[] str = new char[500*8*2]; private static boolean[] isDigit = new boolean[256]; private static boolean[] isSpace = new boolean[256]; private static boolean[] isLineSep = new boolean[256]; static { for(int i = 0; i < 10; i++) { isDigit['0' + i] = true; } isDigit['-'] = true; isSpace[' '] = isSpace['\r'] = isSpace['\n'] = isSpace['\t'] = true; isLineSep['\r'] = isLineSep['\n'] = true; } public byte read() throws IOException { if(pos >= readLen) { pos = 0; readLen = in.read(buffer); if(readLen <= 0) { throw new EndOfFileRuntimeException(); } } return buffer[pos++]; } public int nextInt() throws IOException { byte first = (byte)nextChar(); boolean minus = false; int res = 0; if (first == '-') { minus = true; } else { res = first - '0'; } while (true) { byte b = read(); if (isSpace[b]) break; res = res * 10 + b - '0'; } return minus ? -res : res; } public long nextLong() throws IOException { int len = 0; str[len++] = nextChar(); len = reads(len, isSpace); int i = 0; long ret = 0; if(str[0] == '-') { i = 1; } for(; i < len; i++) ret = ret * 10 + str[i] - '0'; if(str[0] == '-') { ret = -ret; } return ret; } public char nextChar() throws IOException { while(true) { final int c = read(); if(!isSpace[c]) { return (char)c; } } } int reads(int len, boolean[] accept) throws IOException { try { while(true) { final int c = read(); if(accept[c]) { break; } if(str.length == len) { char[] rep = new char[str.length * 3 / 2]; System.arraycopy(str, 0, rep, 0, str.length); str = rep; } str[len++] = (char)c; } } catch(EndOfFileRuntimeException e) { ; } return len; } int reads(char[] cs, int len, boolean[] accept) throws IOException { try { while(true) { final int c = read(); if(accept[c]) { break; } cs[len++] = (char)c; } } catch(EndOfFileRuntimeException e) { ; } return len; } public char[] nextLine() throws IOException { int len = 0; str[len++] = nextChar(); len = reads(len, isLineSep); try { if(str[len-1] == '\r') { len--; read(); } } catch(EndOfFileRuntimeException e) { ; } return Arrays.copyOf(str, len); } public String nextString() throws IOException { return new String(next()); } public char[] next() throws IOException { int len = 0; str[len++] = nextChar(); len = reads(len, isSpace); return Arrays.copyOf(str, len); } // public int next(char[] cs) throws IOException { int len = 0; cs[len++] = nextChar(); len = reads(cs, len, isSpace); return len; } // public double nextDouble() throws IOException { return Double.parseDouble(nextString()); } public double nextDouble() throws IOException { double res = nextChar() - '0'; while (true) { byte c = read(); if (isSpace[c]) return res; if (c == '.') break; res = res * 10 + c - '0'; } double d = 1; while (true) { byte c = read(); // dump(c); if (!isDigit[c]) break; res = res * 10 + c - '0'; d *= 10; } // dump(1); return res / d; } public long[] nextLongArray(final int n) throws IOException { final long[] res = new long[n]; for(int i = 0; i < n; i++) { res[i] = nextLong(); } return res; } public int[] nextIntArray(final int n) throws IOException { final int[] res = new int[n]; for(int i = 0; i < n; i++) { res[i] = nextInt(); } return res; } public int[][] nextIntArray2D(final int n, final int k) throws IOException { final int[][] res = new int[n][]; for(int i = 0; i < n; i++) { res[i] = nextIntArray(k); } return res; } public int[][] nextIntArray2DWithIndex(final int n, final int k) throws IOException { final int[][] res = new int[n][k+1]; for(int i = 0; i < n; i++) { for(int j = 0; j < k; j++) { res[i][j] = nextInt(); } res[i][k] = i; } return res; } public double[] nextDoubleArray(final int n) throws IOException { final double[] res = new double[n]; for(int i = 0; i < n; i++) { res[i] = nextDouble(); } return res; } } }