QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#210147#5037. 回文hos_lyric#0 472ms8584kbC++143.0kb2023-10-11 03:21:522024-07-04 02:18:27

Judging History

你现在查看的是最新测评结果

  • [2024-07-04 02:18:27]
  • 评测
  • 测评结果:0
  • 用时:472ms
  • 内存:8584kb
  • [2023-10-11 03:21:52]
  • 提交

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")


// |as| = n ==> |rs| = 2 n + 1
// [i - rs[i], i + rs[i]] is palindrome for $ as[0] $ as[1] $ ... $ as[n-1] $
// as[i, j): palindrome <=> j - i <= rs[i + j]
template <class String> vector<int> manacher(const String &as) {
  const int n = as.size();
  vector<int> rs(2 * n + 1);
  for (int i = 0, j = 0, k; i <= 2 * n; i += k, j -= k) {
    for (; 0 < i - j && i + j < 2 * n &&
           (!((i + j + 1) & 1) || as[(i - j - 1) >> 1] == as[(i + j + 1) >> 1]);
         ++j) {}
    rs[i] = j;
    for (k = 1; k < j && k + rs[i - k] < j; ++k) rs[i + k] = rs[i - k];
  }
  return rs;
}


char S[200'010];
int N, Q;
vector<int> O, I, L, R;
vector<char> C;


namespace brute {
vector<int> run() {
cerr<<"[brute::run]"<<endl;
  string s = S;
  vector<int> ans;
  int lastans = 0;
  for (int q = 0; q < Q; ++q) {
    if (O[q] == 1) {
      const int i = I[q] ^ lastans;
      s[i] = C[q];
    } else {
      const int l = (L[q] ^ lastans) - 1;
      const int r = R[q] ^ lastans;
      const auto rs = manacher(s);
      int cnt = 0;
      for (int i = l; i < r; ++i) if (rs[i + r] >= r - i) {
        ++cnt;
      }
      ans.push_back(cnt);
      lastans = cnt;
    }
  }
  return ans;
}
}  // brute


int main() {
  for (; ~scanf("%s", S); ) {
    N = strlen(S);
    scanf("%d", &Q);
    O.resize(Q, -1);
    I.resize(Q, -1);
    C.resize(Q, '?');
    L.resize(Q, -1);
    R.resize(Q, -1);
    for (int q = 0; q < Q; ++q) {
      scanf("%d", &O[q]);
      if (O[q] == 1) {
        scanf("%d %c", &I[q], &C[q]);
      } else {
        scanf("%d%d", &L[q], &R[q]);
      }
    }
    
    const auto ans = brute::run();
    for (const int a : ans) {
      printf("%d\n", a);
    }
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 98ms
memory: 3960kb

input:

aabbbabbbaaaaaaabbabbbaaaabaaaabbaabbaabbaaababbbabbbbabbbbaaaabbbabbbbbaaabbbabbaaaaabbbbbaaababbabbaaaaabaabbbbaaababaaabbaabbabbbabbbbaaaaabbbbbbbabbbaabbbabbabbbababbabbbbaaaaabbaababbbbaabbaaaaaabaaabbbaaababbbbaabaaaaababababbbbbbaaaabbbbaaababaaabbaabbbbbaaaabbaaaabaaaaaababbababaaaabaaababaa...

output:

2
3
5
3
3
3
2
3
4
2
4
2
4
2
3
3
3
2
2
2
2
2
3
3
4
2
2
3
2
2
4
3
3
2
3
3
4
2
4
3
2
2
3
4
2
2
4
2
4
2
2
2
2
3
3
3
4
4
3
3
2
3
3
2
3
3
4
2
2
4
2
3
3
3
3
2
3
2
2
3
2
2
3
6
6
2
3
7
4
3
2
2
2
2
3
4
4
4
4
3
2
3
2
4
2
3
2
3
3
2
2
2
2
3
3
4
3
2
2
4
3
2
4
5
4
2
2
5
3
3
3
3
2
6
3
3
2
3
3
3
2
4
4
5
2
2
3
5
3
3
...

result:

wrong answer 23rd words differ - expected: '2', found: '3'

Subtask #2:

score: 0
Time Limit Exceeded

Test #15:

score: 0
Time Limit Exceeded

input:

aabababbabbbbbbabbababaaaabababbabbbbbbabbababaaaabababbabbbbbbabbababaaaabababbabbbbbbabbababaabbbaaabbaabbbbaabbaaabbbaabababbabbbbbbabbababaaaabababbabbbbbbabbababaaaabababbabbbbbbabbababaaaabababbabbbbbbabbababaabbaaabaaaaaabaaabbaabababbabbbbbbabbababaaaabababbabbbbbbabbababaaaabababbabbbbbbabb...

output:


result:


Subtask #3:

score: 0
Wrong Answer

Test #21:

score: 0
Wrong Answer
time: 472ms
memory: 8584kb

input:

abbaaaabbabaaaaaabaabbaabbababbaaabbabbbabaabaabaaaaabaabbbbabbabbabbbababbbababababbbbabaabbaaababbbbbababbbbaabbbaaabaababababaabbbbbbaababaabbaaabaabbaaababbabbabbbbaaaaabaaabbbabbbbbbabbbabbabaabbbbbbbaaaabbaaaababbbaaaaaaababaabbbbaaabaaabbaabbbbbbababbaabbaaabbabbbbbabaababbaabaaaabbbbabababba...

output:

2
2
3
3
3
3
3
3
3
3
3
3
3
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
7
4
2
2
...

result:

wrong answer 3rd words differ - expected: '2', found: '3'

Subtask #4:

score: 0
Time Limit Exceeded

Test #27:

score: 0
Time Limit Exceeded

input:

babbaaabbbbbbbabbbababaabbbbbababababbaabaabbbbbbabbbbbbbbbbababbbbabbaabbbaabaabbabbbaabbabbbabbababaababbbabbbbaabbabbabbaaaabbbaaabbbbaabbaaaaaaabbbabbbaaabaababaaabaaaabaaaababaaaaababaaaabaabbaaaabbbabbaabaabbbabbbbbaaabaababbbaaaaabbbbaaabbbbaabbabbbbabbbabbaaaaabaabaaaabbbabbbbbaabbbbabbbbaab...

output:


result:


Subtask #5:

score: 0
Skipped

Dependency #1:

0%

Subtask #6:

score: 0
Skipped

Dependency #1:

0%