QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#69590#5233. Wielki Zderzacz Termionów [A]zgliczCompile Error//C++205.4kb2022-12-28 20:58:312022-12-28 20:58:32

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-12-28 20:58:32]
  • 评测
  • [2022-12-28 20:58:31]
  • 提交

answer

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <array>
#include <random>
#include <cmath>
#include <chrono>
#include <list>
#include <ctime>
#include <sstream>
#include <queue>
#include <climits>
#include <stack>
#include <valarray>
#include <random>
#include <bitset>
#include <numeric>
#include <iomanip>
#include <cassert>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
#define rep(x, b, e) for(int x=(b); x<(e); ++x)
#define trav(a, x) for(auto& a : x)
#define ford(x, b, e) for(int x=((int)(b))-1; x>=(e); --x)
#define all(c) c.begin(),c.end()
#define sz(x) ((int)((x).size()))
#define pb push_back
#define eb emplace_back
#define st first
#define nd second
#define mp(x,y) make_pair(x,y)
typedef short int sint;
template<typename T> bool ckmin(T& a, const T& b){return b<a?a=b,1:0;}
template<typename T> bool ckmax(T& a, const T& b){return b>a?a=b,1:0;}


template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(char c) {
  return string(1, c);
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif


#include <atcoder/segtree>
#include <atcoder/modint>
using namespace atcoder;
using mint = modint1000000007;
typedef vector<mint> vmi;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); // use rng() to get unsigned int
// mt19937_64 for random long longs

struct S {
  vmi ways;
  S() {
    ways.assign(3, 0);
  }
  S(char a) {
    if (a == 'N') {
      ways = {0, 1, 1};
    } else if (a == 'C') {
      ways = {0, 1, 0};
    } else {
      ways = {0, 0, 1};
    }
  }
};

S op(S a, S b) {
  S c;
  rep(i, 0, 3) {
    rep(j, 0, 3) {
      int k = (i + j) % 3;
      c.ways[k] += a.ways[i] * b.ways[j];
    }
  }
  return c;
}

S e() {
  S ans;
  ans.ways[0] = 1;
  return ans;
}

void solve() {
	int n, q;
  cin >> n >> q;
  // n = 2e5;
  // q = 1e5;
  string x;
  cin >> x;
  // vector<char> zn = {'C', 'Z', 'N'};
  // rep(i, 0, n) {
  //   x += zn[rng() % 3];
  // }
  vector<S> a;

  vi cs(2); // count non matching
  vi zs(2); // count non matching
  auto modLetter = [&](char letter, int idx, int val) {
    if (letter == 'N') {
      cs[idx&1] += val;
      zs[idx&1] += val;
    } else if (letter == 'C') {
      cs[idx&1] += val;
    } else {
      zs[idx&1] += val;
    }
  };
  auto addLetter = [&](char letter, int idx) {
    modLetter(letter, idx, 1);
  };
  auto removeLetter = [&](char letter, int idx) {
    modLetter(letter, idx, -1);
  };

  rep(i, 0, n) {
    a.pb(S(x[i]));
    addLetter(x[i], i);
  }

  auto cntOddEve = [&]() {
    int ans = 0;
    if (n == 1) return ans;
    if (n%2 == 0) return ans;
    if (cs[0] + zs[1] == n) ++ans;
    if (zs[0] + cs[1] == n) ++ans;
    debug(cs, zs, ans);
    return ans;
  };
  segtree<S, op, e> seg(a);
  auto result = [&]() {
    auto h = seg.all_prod();
    return h.ways[1] + h.ways[2] - cntOddEve();
  };
  cout << result().val() << '\n';
  while (q--) {
    int idx;
    char now;
    cin >> idx >> now;
    // idx = rng() % n + 1;
    // now = zn[rng() % 3];
    --idx;
    removeLetter(x[idx], idx);
    seg.set(idx, S(now));
    x[idx] = now;
    addLetter(x[idx], idx);
    cout << result().val() << '\n';
  }
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	int t;
	// cin >> t;
	t = 1;
	while (t--) {
		solve();
	}
}

Details

answer.code:136:10: fatal error: atcoder/segtree: No such file or directory
  136 | #include <atcoder/segtree>
      |          ^~~~~~~~~~~~~~~~~
compilation terminated.