結果
問題 | No.255 Splarrraaay スプラーレェーーイ |
ユーザー | uwi |
提出日時 | 2015-07-24 23:31:14 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 1,728 ms / 10,000 ms |
コード長 | 8,560 bytes |
コンパイル時間 | 4,202 ms |
コンパイル使用メモリ | 89,032 KB |
実行使用メモリ | 147,372 KB |
最終ジャッジ日時 | 2024-10-12 19:23:59 |
合計ジャッジ時間 | 20,391 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1,728 ms
146,996 KB |
testcase_01 | AC | 1,713 ms
147,048 KB |
testcase_02 | AC | 1,429 ms
146,904 KB |
testcase_03 | AC | 1,440 ms
147,372 KB |
testcase_04 | AC | 53 ms
49,932 KB |
testcase_05 | AC | 1,438 ms
146,672 KB |
testcase_06 | AC | 1,444 ms
146,780 KB |
testcase_07 | AC | 1,416 ms
146,752 KB |
testcase_08 | AC | 1,381 ms
146,768 KB |
testcase_09 | AC | 1,474 ms
147,280 KB |
ソースコード
package contest; 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 Q637 { InputStream is; PrintWriter out; String INPUT = ""; static long mod = 1000000000000000009L; void solve() { long n = nl(); int Q = ni(); long[][] qs = new long[Q][]; long[] xi = new long[Q*2]; for(int i = 0;i < Q;i++){ qs[i] = new long[]{ni(), nl(), nl()+1}; } for(int i = 0;i < Q;i++){ xi[i*2] = qs[i][1]<<19|i*2; xi[i*2+1] = qs[i][2]<<19|i*2+1; } Arrays.sort(xi); long[] imap = new long[Q*2]; int p = 0; for(int i = 0;i < Q*2;i++){ if(i == 0 || xi[i]>>>19 != xi[i-1]>>>19){ imap[p++] = xi[i]>>>19; } int ind = (int)(xi[i]&(1L<<19)-1); if((ind&1) == 0){ qs[ind/2][1] = p-1; }else{ qs[ind/2][2] = p-1; } } long[] score = new long[6]; long[][] bon = new long[Q][6]; for(int k = 1;k <= 5;k++){ SegmentTreeOverwriteRSQ1D st = new SegmentTreeOverwriteRSQ1D(imap); for(int i = 0;i < Q;i++){ int t = (int)qs[i][0]; int L = (int)qs[i][1]; int R = (int)qs[i][2]; if(t == 0){ bon[i][k] = st.sum(L, R); }else if(t == k){ st.add(L, R, 1L); }else{ st.update(L, R, 0); } } score[k] = st.sum[1]; } for(int i = 0;i < Q;i++){ if(qs[i][0] == 0){ long lmax = -1; for(int j = 1;j <= 5;j++){ lmax = Math.max(lmax, bon[i][j]); } int hit = 0; int last = -1; for(int j = 1;j <= 5;j++){ if(lmax == bon[i][j]){ hit++; last = j; } } if(hit == 1){ score[last] += bon[i][last]; score[last] %= mod; } } } for(int i = 1;i <= 5;i++){ if(i > 1)out.print(" "); out.print(score[i]%mod); } out.println(); } public static class SegmentTreeOverwriteRSQ1D { public int M, H, N; public long[] sum; public long[] plus; public long[] cover; private long I = Long.MAX_VALUE; public long[] lens; public long[] co; public SegmentTreeOverwriteRSQ1D(long[] co) { this.co = co; N = co.length; M = Integer.highestOneBit(Math.max(N-1, 1))<<2; H = M>>>1; cover = new long[H]; Arrays.fill(cover, I); plus = new long[H]; sum = new long[M]; Arrays.fill(sum, 0L); lens = new long[M]; for(int i = 0;i < N-1;i++){ lens[i+H] = co[i+1]-co[i]; } for(int i = H-1;i >= 1;i--){ lens[i] = lens[2*i] + lens[2*i+1]; propagate(i); } } private void propagate(int i) { if(cover[i] == I){ sum[i] = sum[2*i] + sum[2*i+1] + plus[i] * lens[i]; }else{ sum[i] = (cover[i] + plus[i]) * lens[i]; } } public void update(int l, int r, int v){ update(l, r, v, 0, H, 1); } private void update(int l, int r, int v, int cl, int cr, int cur) { if(l <= cl && cr <= r){ if(cr == cl+1){ sum[cur] = v*lens[cur]; }else{ cover[cur] = v; plus[cur] = 0; propagate(cur); } }else{ int mid = cl+cr>>>1; boolean bp = false; if(cover[cur] != I){ // back-propagate cover if(2*cur >= H){ sum[2*cur] = cover[cur] * lens[2*cur]; sum[2*cur+1] = cover[cur] * lens[2*cur+1]; }else{ cover[2*cur] = cover[2*cur+1] = cover[cur]; plus[2*cur] = plus[2*cur+1] = 0; bp = true; } cover[cur] = I; } { // back-propagate plus&slope if(2*cur >= H){ sum[2*cur] += plus[cur] * lens[2*cur]; sum[2*cur+1] += plus[cur] * lens[2*cur+1]; }else{ plus[2*cur] += plus[cur]; plus[2*cur+1] += plus[cur]; bp = true; } plus[cur] = 0; } if(cl < r && l < mid){ update(l, r, v, cl, mid, 2*cur); }else if(bp){ propagate(2*cur); } if(mid < r && l < cr){ update(l, r, v, mid, cr, 2*cur+1); }else if(bp){ propagate(2*cur+1); } propagate(cur); } } public void add(int l, int r, long v){ add(l, r, v, 0, H, 1); } private void add(int l, int r, long v, int cl, int cr, int cur) { if(l <= cl && cr <= r){ if(cr == cl+1){ sum[cur] += v * lens[cur]; }else{ plus[cur] += v; propagate(cur); } }else{ int mid = cl+cr>>>1; boolean bp = false; if(cover[cur] != I){ // back-propagate cover if(2*cur >= H){ sum[2*cur] = cover[cur] * lens[2*cur]; sum[2*cur+1] = cover[cur] * lens[2*cur+1]; }else{ cover[2*cur] = cover[2*cur+1] = cover[cur]; plus[2*cur] = plus[2*cur+1] = 0; bp = true; } cover[cur] = I; } { // back-propagate plus&slope if(2*cur >= H){ sum[2*cur] += plus[cur] * lens[2*cur]; sum[2*cur+1] += plus[cur] * lens[2*cur+1]; }else{ plus[2*cur] += plus[cur]; plus[2*cur+1] += plus[cur]; bp = true; } plus[cur] = 0; } if(cl < r && l < mid){ add(l, r, v, cl, mid, 2*cur); }else if(bp){ propagate(2*cur); } if(mid < r && l < cr){ add(l, r, v, mid, cr, 2*cur+1); }else if(bp){ propagate(2*cur+1); } propagate(cur); } } public long sum(int l, int r){ return sum(l, r, 0, H, 1); } private long sum(int l, int r, int cl, int cr, int cur) { if(l <= cl && cr <= r){ return sum[cur]; }else{ long inter = co[Math.min(cr, r)] - co[Math.max(cl, l)]; if(cover[cur] != I){ long ret = (cover[cur] + plus[cur]) * inter; return ret; } int mid = cl+cr>>>1; long ret = 0; if(cl < r && l < mid){ ret += sum(l, r, cl, mid, 2*cur); } if(mid < r && l < cr){ ret += sum(l, r, mid, cr, 2*cur+1); } ret += plus[cur] * inter; return ret; } } // public int[] toArray() { return toArray(1, 0, H, new int[H]); } // // private int[] toArray(int cur, int l, int r, int[] ret) // { // if(r-l == 1){ // ret[cur-H] = sum[cur]; // }else if(cover[cur] != I){ // Arrays.fill(ret, l, r, cover[cur]); // }else{ // toArray(2*cur, l, l+r>>>1, ret); // toArray(2*cur+1, l+r>>>1, r, ret); // } // return ret; // } } void run() throws Exception { is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes()); out = new PrintWriter(System.out); long s = System.currentTimeMillis(); solve(); out.flush(); if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms"); } public static void main(String[] args) throws Exception { new Q637().run(); } private byte[] inbuf = new byte[1024]; private int lenbuf = 0, ptrbuf = 0; private 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 boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; } private double nd() { return Double.parseDouble(ns()); } private char nc() { return (char)skip(); } private String ns() { int b = skip(); StringBuilder sb = new StringBuilder(); while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ') sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } private char[] ns(int n) { char[] buf = new char[n]; int b = skip(), p = 0; while(p < n && !(isSpaceChar(b))){ buf[p++] = (char)b; b = readByte(); } return n == p ? buf : Arrays.copyOf(buf, p); } private char[][] nm(int n, int m) { char[][] map = new char[n][]; for(int i = 0;i < n;i++)map[i] = ns(m); return map; } private int[] na(int n) { int[] a = new int[n]; for(int i = 0;i < n;i++)a[i] = ni(); return a; } private 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 long nl() { long num = 0; int 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) { System.out.println(Arrays.deepToString(o)); } }