示例#1
1
 public void solve(int testNumber, FastScanner in, FastPrinter out) {
   int n = in.nextInt();
   int p = in.nextInt();
   int m = in.nextInt();
   Query[] qs = new Query[m];
   int[] z = new int[4 * m + 10];
   int cn = 0;
   for (int i = 0; i < m; i++) {
     int time = in.nextInt();
     int type = in.next().equals("save") ? 0 : 1;
     int a = in.nextInt();
     int b = in.nextInt();
     qs[i] = new Query(time, type, a, b);
     if (type == 0) {
       z[cn++] = a - 1;
       z[cn++] = b;
     } else {
       --a;
       z[cn++] = a - b + 1;
       z[cn++] = a;
       z[cn++] = a + b;
     }
   }
   z[cn++] = 0;
   z[cn++] = n;
   z = Arrays.copyOf(z, cn);
   z = ArrayUtils.sortAndUnique(z);
   int[] cnt = new int[z.length - 1];
   {
     for (int i = 0; i < z.length - 1; i++) {
       cnt[i] = z[i + 1] - z[i];
     }
   }
   SegmentTree tree = new SegmentTree(cnt);
   int last = 0;
   double all = 0;
   for (int i = 0; i < m; i++) {
     int time = qs[i].time;
     tree.addValue(0, cnt.length, 1. * p * (time - last), 0);
     last = time;
     if (qs[i].type == 0) {
       int l = qs[i].a - 1;
       int r = qs[i].b;
       l = Arrays.binarySearch(z, l);
       r = Arrays.binarySearch(z, r);
       double sum = tree.getSum(l, r);
       all += sum;
       out.println(all);
       tree.setZero(l, r);
     } else {
       int index = qs[i].a - 1;
       int d = qs[i].b;
       double x = all / (2 * SegmentTree.sum(d) + d);
       int id = Arrays.binarySearch(z, index);
       tree.addValue(Arrays.binarySearch(z, index - d + 1), id, x, x);
       tree.addValue(id, Arrays.binarySearch(z, index + d), d * x, -x);
       all = 0;
     }
   }
 }
示例#2
0
 public void solve(int testNumber, FastScanner in, FastPrinter out) {
   int n = in.nextInt();
   String s = in.next();
   f = new int[primes.length];
   add = new int[10][primes.length];
   for (int d = 2; d < 10; d++) {
     int[] f = add[d];
     for (int i = 0; i < primes.length; i++) {
       int p = primes[i];
       int x = d;
       while (x > 0) {
         x /= p;
         f[i] += x;
       }
     }
   }
   for (char c : s.toCharArray()) {
     int d = c - '0';
     if (d <= 1) continue;
     for (int i = 0; i < primes.length; i++) {
       f[i] += add[d][i];
     }
   }
   g = new int[primes.length];
   x = new int[100];
   if (go(0, 9)) {
     for (int i = 0; i < len; i++) {
       out.print(x[i]);
     }
     out.println();
   } else {
     throw new AssertionError();
   }
 }