fork download
  1. import java.io.BufferedReader;
  2. import java.io.InputStreamReader;
  3.  
  4. public class Main {
  5. private static long[] t;
  6. private static long[]codes;
  7. private static final long prime = 61;
  8. private static long[] pows;
  9. private static void build (int v, int tl, int tr) {
  10. if (tl == tr){
  11. t[v] = (codes[tl] * pows[tl - 1]);
  12. }
  13. else {
  14. int tm = (tl + tr) / 2;
  15. build (2 * v, tl, tm);
  16. build (2 * v + 1, tm + 1, tr);
  17. t[v] = (t[2 * v] + t[2 * v + 1]);
  18. }
  19. }
  20.  
  21. private static long sum (int v, int tl, int tr, int l, int r) {
  22. if (l > r){
  23. return 0;
  24. }
  25. if (l == tl && r == tr)
  26. return t[v];
  27. int tm = (tl + tr) / 2;
  28. return sum (2 * v, tl, tm, l, Math.min(r, tm))
  29. + sum (2 * v + 1, tm + 1, tr, Math.max(l, tm + 1), r);
  30. }
  31.  
  32. private static void update (int v, int tl, int tr, int pos, long newVal) {
  33. if (tl == tr)
  34. t[v] = (newVal * pows[pos - 1]);
  35. else {
  36. int tm = (tl + tr) / 2;
  37. if (pos <= tm)
  38. update (v*2, tl, tm, pos, newVal);
  39. else
  40. update (2 * v + 1, tm + 1, tr, pos, newVal);
  41. t[v] = (t[2 * v] + t[2 * v + 1]);
  42. }
  43. }
  44. public static void main(String[] args) throws Exception{
  45. BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
  46. String[] params = bufferedReader.readLine().split(" ");
  47. int n = Integer.parseInt(params[0]);
  48. codes = new long[n + 1];
  49. pows = new long[n + 1];
  50. t = new long[4 * n];
  51. int k = Integer.parseInt(params[1]);
  52. String a = bufferedReader.readLine();
  53. for (int i = 1; i <= n; i++) {
  54. codes[i] = a.charAt(i - 1) - 'A' + 1;
  55. }
  56. pows[0] = 1;
  57. for (int i = 1; i <= n; i++) {
  58. pows[i] = pows[i - 1] * prime;
  59. }
  60. build(1, 1, n);
  61. for (int t = 0; t <k; t++) {
  62. char q = (char) bufferedReader.read();
  63. bufferedReader.skip(1);
  64. if (q == '?') {
  65. String[] query = bufferedReader.readLine().split(" ");
  66. int i = Integer.parseInt(query[0]);
  67. int j = Integer.parseInt(query[1]);
  68. int len = Integer.parseInt(query[2]);
  69. if (i > j) {
  70. int temp = i;
  71. i = j;
  72. j = temp;
  73. }
  74. // System.out.println(sum(1, 1, n, i, i + len - 1) * pows[j - i]);
  75. // System.out.println( sum(1, 1, n, j, j + len - 1));
  76. if(sum(1, 1, n, i, i + len - 1) * pows[j - i] == sum(1, 1, n, j, j + len - 1)){
  77. System.out.print("+");
  78. }
  79. else{
  80. System.out.print("-");
  81. }
  82. }
  83. else if(q == '*') {
  84. String[] query = bufferedReader.readLine().split(" ");
  85. int temp = Integer.parseInt(query[0]);
  86. char c = query[1].charAt(0);
  87. update(1, 1, n, temp, c - 'A' + 1);
  88. }
  89. }
  90. }
  91. }
Runtime error #stdin #stdout #stderr 0.04s 2184192KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Exception in thread "main" java.lang.NullPointerException
	at Main.main(Main.java:46)