QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#413585 | #1286. Ternary String Counting | lifan | Compile Error | / | / | C++14 | 3.9kb | 2024-05-17 19:29:17 | 2024-05-17 19:29:17 |
Judging History
answer
//
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using i64 = long long;
using i128 = __int128_t;
using u32 = unsigned int;
using u64 = unsigned long long;
using u128 = __uint128_t;
void set_io(std::string name)
{
#ifndef NO_FREOPEN
freopen((name + ".in").c_str(), "r", stdin);
freopen((name + ".out").c_str(), "w", stdout);
#endif
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
}
template <int M>
struct static_modint
{
static constexpr u32 UM = M;
static_assert(UM < 0x80'00'00'00u);
u32 v;
constexpr static_modint() : v(0) {}
template <typename T, std::enable_if_t<std::is_signed_v<T>>* = nullptr>
constexpr static_modint(T n) : v((n %= M) < 0 ? n + M : n) {}
template <typename T, std::enable_if_t<std::is_unsigned_v<T>>* = nullptr>
constexpr static_modint(T n) : v(n %= UM) {}
using mint = static_modint;
static mint raw(u32 v)
{
mint res;
res.v = v;
return res;
}
constexpr u32 val() const { return v; }
mint operator-() const { return mint::raw(v == 0 ? 0u : M - v); }
mint &operator+=(mint a)
{
if ((v += a.v) >= M) v -= M;
return *this;
}
mint &operator-=(mint a)
{
if ((v += M - a.v) >= M) v -= M;
return *this;
}
mint &operator*=(mint a)
{
v = (u64)v * a.v % M;
return *this;
}
mint &operator/=(mint a) { return *this *= a.inv(); }
friend mint operator+(mint a, mint b) { return a += b; }
friend mint operator-(mint a, mint b) { return a -= b; }
friend mint operator*(mint a, mint b) { return a *= b; }
friend mint operator/(mint a, mint b) { return a /= b; }
mint pow(u64 n) const
{
mint res = 1, base = *this;
while (n) {
if (n & 1) res *= base;
base *= base;
n >>= 1;
}
return res;
}
mint inv() const { return pow(M - 2); }
};
using mint = static_modint<1'000'000'007>;
void solve()
{
int N, M;
std::cin >> N >> M;
// j in [jl, jr), k in [kl, kr)
std::vector<int> jl(N + 1, 0), jr(N + 1, N + 1), kl(N + 1, 0), kr(N + 1, N + 1);
for (int i = 0; i < M; i++) {
int l, r, x;
std::cin >> l >> r >> x;
if (x == 1) {
jr[r] = std::min(jr[r], l);
} else if (x == 2) {
jl[r] = std::max(jl[r], l);
kr[r] = std::min(kr[r], l);
} else if (x == 3) {
kl[r] = std::max(kl[r], l);
}
}
std::vector f(N + 1, std::vector<mint>(N + 1));
f[0][0] = 1;
std::vector<mint> rows(N + 1), cols(N + 1);
rows[0] = 1;
cols[0] = 1;
std::vector<int> l(N + 1, 0), r(N + 1, N + 1);
auto fix = [&](int i, int ll, int rr)
{
ll = std::min(ll, r[i]);
rr = std::max(rr, l[i]);
ll = std::max(ll, l[i]);
rr = std::min(rr, r[i]);
for (int j = l[i]; j < ll; j++) {
rows[i] -= f[i][j];
cols[j] -= f[i][j];
f[i][j] = 0;
}
for (int j = rr; j < r[i]; j++) {
rows[i] -= f[i][j];
cols[j] -= f[i][j];
f[i][j] = 0;
}
l[i] = ll;
r[i] = rr;
};
for (int i = 0; i < N; i++) {
std::vector<mint> drows(N + 1), dcols(N + 1);
for (int j = jl[i]; j < jr[i]; j++) {
f[i][j] += rows[j];
drows[i] += rows[j];
dcols[j] += rows[j];
}
for (int j = kl[i]; j < kr[i]; j++) {
f[i][j] += cols[j];
drows[i] += cols[j];
dcols[j] += cols[j];
}
for (int j = 0; j <= N; j++) {
rows[j] += drows[j];
cols[j] += dcols[j];
}
int jli = jl[i + 1], jri = jr[i + 1], kli = kl[i + 1], kri = kr[i + 1];
for (int j = 0; j < jli && j <= i; j++) fix(j, 0, 0);
for (int j = jli; j < jri && j <= i; j++) fix(j, kli, kri);
for (int j = jri; j <= i; j++) fix(j, 0, 0);
}
mint ans = 0;
for (int i = 0; i <= N; i++) ans += rows[i];
std::cout << ans.val() << std::endl;
}
int main()
{
int t;
std::cin >> t;
while (t--) solve();
}
详细
answer.code:32:47: error: ‘is_signed_v’ is not a member of ‘std’; did you mean ‘is_signed’? 32 | template <typename T, std::enable_if_t<std::is_signed_v<T>>* = nullptr> | ^~~~~~~~~~~ | is_signed answer.code:32:47: error: ‘is_signed_v’ is not a member of ‘std’; did you mean ‘is_signed’? 32 | template <typename T, std::enable_if_t<std::is_signed_v<T>>* = nullptr> | ^~~~~~~~~~~ | is_signed answer.code:32:59: error: template argument 1 is invalid 32 | template <typename T, std::enable_if_t<std::is_signed_v<T>>* = nullptr> | ^ answer.code:32:64: error: expected unqualified-id before ‘=’ token 32 | template <typename T, std::enable_if_t<std::is_signed_v<T>>* = nullptr> | ^ answer.code:35:47: error: ‘is_unsigned_v’ is not a member of ‘std’; did you mean ‘is_unsigned’? 35 | template <typename T, std::enable_if_t<std::is_unsigned_v<T>>* = nullptr> | ^~~~~~~~~~~~~ | is_unsigned answer.code:35:47: error: ‘is_unsigned_v’ is not a member of ‘std’; did you mean ‘is_unsigned’? 35 | template <typename T, std::enable_if_t<std::is_unsigned_v<T>>* = nullptr> | ^~~~~~~~~~~~~ | is_unsigned answer.code:35:61: error: template argument 1 is invalid 35 | template <typename T, std::enable_if_t<std::is_unsigned_v<T>>* = nullptr> | ^ answer.code:35:66: error: expected unqualified-id before ‘=’ token 35 | template <typename T, std::enable_if_t<std::is_unsigned_v<T>>* = nullptr> | ^ answer.code: In function ‘void solve()’: answer.code:110:15: error: missing template arguments before ‘f’ 110 | std::vector f(N + 1, std::vector<mint>(N + 1)); | ^ answer.code:111:3: error: ‘f’ was not declared in this scope 111 | f[0][0] = 1; | ^ answer.code:113:13: error: no match for ‘operator=’ (operand types are ‘__gnu_cxx::__alloc_traits<std::allocator<static_modint<1000000007> >, static_modint<1000000007> >::value_type’ {aka ‘static_modint<1000000007>’} and ‘int’) 113 | rows[0] = 1; | ^ answer.code:24:8: note: candidate: ‘constexpr static_modint<1000000007>& static_modint<1000000007>::operator=(const static_modint<1000000007>&)’ 24 | struct static_modint | ^~~~~~~~~~~~~ answer.code:24:8: note: no known conversion for argument 1 from ‘int’ to ‘const static_modint<1000000007>&’ answer.code:24:8: note: candidate: ‘constexpr static_modint<1000000007>& static_modint<1000000007>::operator=(static_modint<1000000007>&&)’ answer.code:24:8: note: no known conversion for argument 1 from ‘int’ to ‘static_modint<1000000007>&&’ answer.code:114:13: error: no match for ‘operator=’ (operand types are ‘__gnu_cxx::__alloc_traits<std::allocator<static_modint<1000000007> >, static_modint<1000000007> >::value_type’ {aka ‘static_modint<1000000007>’} and ‘int’) 114 | cols[0] = 1; | ^ answer.code:24:8: note: candidate: ‘constexpr static_modint<1000000007>& static_modint<1000000007>::operator=(const static_modint<1000000007>&)’ 24 | struct static_modint | ^~~~~~~~~~~~~ answer.code:24:8: note: no known conversion for argument 1 from ‘int’ to ‘const static_modint<1000000007>&’ answer.code:24:8: note: candidate: ‘constexpr static_modint<1000000007>& static_modint<1000000007>::operator=(static_modint<1000000007>&&)’ answer.code:24:8: note: no known conversion for argument 1 from ‘int’ to ‘static_modint<1000000007>&&’ answer.code:161:14: error: conversion from ‘int’ to non-scalar type ‘mint’ {aka ‘static_modint<1000000007>’} requested 161 | mint ans = 0; | ^ answer.code: In function ‘void set_io(std::string)’: answer.code:16:10: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 16 | freopen((name + ".in").c_str(), "r", stdin); | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ answer.code:17:10: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 17 | freopen((name + ".out").c_str(), "w", stdout); | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~