fea: more contests
This commit is contained in:
parent
00d23dc313
commit
c65a12a652
103 changed files with 3871 additions and 143 deletions
36
codeforces/993/.clangd
Normal file
36
codeforces/993/.clangd
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
CompileFlags:
|
||||
Add:
|
||||
-O2
|
||||
-Wall
|
||||
-Wextra
|
||||
-Wpedantic
|
||||
-Wshadow
|
||||
-Wformat=2
|
||||
-Wfloat-equal
|
||||
-Wlogical-op
|
||||
-Wshift-overflow=2
|
||||
-Wnon-virtual-dtor
|
||||
-Wold-style-cast
|
||||
-Wcast-qual
|
||||
-Wuseless-cast
|
||||
-Wno-sign-promotion
|
||||
-Wcast-align
|
||||
-Wunused
|
||||
-Woverloaded-virtual
|
||||
-Wconversion
|
||||
-Wsign-conversion
|
||||
-Wmisleading-indentation
|
||||
-Wduplicated-cond
|
||||
-Wduplicated-branches
|
||||
-Wlogical-op
|
||||
-Wnull-dereference
|
||||
-Wformat=2
|
||||
-Wformat-overflow
|
||||
-Wformat-truncation
|
||||
-Wdouble-promotion
|
||||
-Wundef
|
||||
-DLOCAL
|
||||
-Wno-unknown-pragmas
|
||||
-std=c++23
|
||||
-std=c++23
|
||||
-std=c++23
|
||||
|
|
@ -1,5 +1,30 @@
|
|||
-std=c++20
|
||||
-O2
|
||||
-Wall
|
||||
-Wextra
|
||||
-Wpedantic
|
||||
-Wshadow
|
||||
-Wformat=2
|
||||
-Wfloat-equal
|
||||
-Wlogical-op
|
||||
-Wshift-overflow=2
|
||||
-Wnon-virtual-dtor
|
||||
-Wold-style-cast
|
||||
-Wcast-qual
|
||||
-Wuseless-cast
|
||||
-Wno-sign-promotion
|
||||
-Wcast-align
|
||||
-Wunused
|
||||
-Woverloaded-virtual
|
||||
-Wconversion
|
||||
-Wmisleading-indentation
|
||||
-Wduplicated-cond
|
||||
-Wduplicated-branches
|
||||
-Wlogical-op
|
||||
-Wnull-dereference
|
||||
-Wformat=2
|
||||
-Wformat-overflow
|
||||
-Wformat-truncation
|
||||
-Wdouble-promotion
|
||||
-Wundef
|
||||
-DLOCAL
|
||||
-std=c++23
|
||||
|
|
|
|||
14
codeforces/993/debug_flags.txt
Normal file
14
codeforces/993/debug_flags.txt
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
-g3
|
||||
-fsanitize=address,undefined
|
||||
-fsanitize=float-divide-by-zero
|
||||
-fsanitize=float-cast-overflow
|
||||
-fno-sanitize-recover=all
|
||||
-fstack-protector-all
|
||||
-fstack-usage
|
||||
-fno-omit-frame-pointer
|
||||
-fno-inline
|
||||
-ffunction-sections
|
||||
-D_GLIBCXX_DEBUG
|
||||
-D_GLIBCXX_DEBUG_PEDANTIC
|
||||
-DLOCAL
|
||||
-std=c++20
|
||||
|
|
@ -1,137 +0,0 @@
|
|||
#include <bits/stdc++.h>
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
template <typename... Args>
|
||||
void dbg(std::string const &str, Args &&...args) {
|
||||
std::cout << std::vformat(str,
|
||||
// make_format_args binds arguments to const
|
||||
std::make_format_args(args...));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void dbg(T const &t) {
|
||||
std::cout << t;
|
||||
}
|
||||
|
||||
template <std::ranges::range T>
|
||||
void dbgln(T const &t) {
|
||||
if constexpr (std::is_convertible_v<T, char const *>) {
|
||||
std::cout << t << '\n';
|
||||
} else {
|
||||
for (auto const &e : t) {
|
||||
std::cout << e << ' ';
|
||||
}
|
||||
std::cout << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void dbgln(std::string const &str, Args &&...args) {
|
||||
dbg(str, std::forward<Args>(args)...);
|
||||
cout << '\n';
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void dbgln(T const &t) {
|
||||
dbg("{}\n", t);
|
||||
}
|
||||
|
||||
void println() {
|
||||
std::cout << '\n';
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
constexpr auto MIN = std::numeric_limits<T>::min();
|
||||
|
||||
template <typename T>
|
||||
constexpr auto MAX = std::numeric_limits<T>::min();
|
||||
|
||||
#define ff first
|
||||
#define ss second
|
||||
#define eb emplace_back
|
||||
#define ll long long
|
||||
#define ld long double
|
||||
#define vec vector
|
||||
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (r).rbegin(), (x).rend()
|
||||
#define sz(x) static_cast<int>((x).size())
|
||||
#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a))
|
||||
#define ROF(a, b, c) for (int(a) = (b); (a) > (c); --(a))
|
||||
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
|
||||
void YES() {
|
||||
cout << "YES\n";
|
||||
}
|
||||
|
||||
void NO() {
|
||||
cout << "NO\n";
|
||||
}
|
||||
|
||||
void solve() {
|
||||
int n, q;
|
||||
cin >> n;
|
||||
vec<vec<int>> grid(n, vec<int>(n));
|
||||
FOR(i, 0, n) {
|
||||
FOR(j, 0, n) {
|
||||
cin >> grid[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
vec<vec<int>> dp(n + 1, vec<int>(n + 1, 1));
|
||||
|
||||
while (q--) {
|
||||
int x1, x2, y1, y2;
|
||||
cin >> x1 >> x2 >> y1 >> y2;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
00 01 02 03 04 05 ...
|
||||
10 11 12 13 14 15 ...
|
||||
|
||||
1 * 00 * 2 * 01 + 3 * 02
|
||||
4 * 01 + 5 *
|
||||
|
||||
1 * M[i][j] + 2 * M[i][j + 1] + 3 * M[i][j + 2]
|
||||
+ 4 * M[i + 1][j] + 5 * M[i + 1][j + 2]
|
||||
|
||||
= sum r0 * n + c0 -> r1 * n + c1
|
||||
|
||||
1 2
|
||||
3 4
|
||||
5 6
|
||||
|
||||
1 2 0 0
|
||||
1 2 + 2 2
|
||||
1 2 + 4 4
|
||||
|
||||
3+4^2+8^3+9^4+13^5+14^6
|
||||
|
||||
8+9^2+13^3+14^4 - ( 8^2+9^2+13^2 )
|
||||
*/
|
||||
// FIX: cout
|
||||
|
||||
dbgln("hi");
|
||||
}
|
||||
|
||||
int main() {
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
127
codeforces/993/h.cpp
Normal file
127
codeforces/993/h.cpp
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
using i32 = int32_t;
|
||||
using u32 = uint32_t;
|
||||
using i64 = int64_t;
|
||||
using u64 = uint64_t;
|
||||
using f64 = double;
|
||||
using f128 = long double;
|
||||
|
||||
#if __cplusplus >= 202002L
|
||||
template <typename T>
|
||||
constexpr T MIN = std::numeric_limits<T>::min();
|
||||
|
||||
template <typename T>
|
||||
constexpr T MAX = std::numeric_limits<T>::max();
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sc(auto&& x) {
|
||||
return static_cast<T>(x);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sz(auto&& x) {
|
||||
return static_cast<T>(x.size());
|
||||
}
|
||||
#endif
|
||||
|
||||
static void NO() {
|
||||
std::cout << "NO\n";
|
||||
}
|
||||
|
||||
static void YES() {
|
||||
std::cout << "YES\n";
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
using vec = std::vector<T>;
|
||||
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
#define ff first
|
||||
#define ss second
|
||||
|
||||
#ifdef LOCAL
|
||||
#define db(...) std::print(__VA_ARGS__)
|
||||
#define dbln(...) std::println(__VA_ARGS__)
|
||||
#else
|
||||
#define db(...)
|
||||
#define dbln(...)
|
||||
#endif
|
||||
// }}}
|
||||
|
||||
void solve() {
|
||||
u32 n, q;
|
||||
cin >> n >> q;
|
||||
|
||||
vec<vec<u64>> grid(n, vec<u64>(n));
|
||||
|
||||
for (auto& r : grid)
|
||||
for (auto& c : r)
|
||||
cin >> c;
|
||||
|
||||
vec<vec<u64>> one(n + 1, vec<u64>(n + 1, 0));
|
||||
auto colwise = one;
|
||||
auto rowwise = one;
|
||||
|
||||
for (u32 i = 1; i <= n; ++i) {
|
||||
for (u32 j = 1; j <= n; ++j) {
|
||||
one[i][j] = grid[i - 1][j - 1] + one[i - 1][j] + one[i][j - 1] -
|
||||
one[i - 1][j - 1];
|
||||
}
|
||||
}
|
||||
|
||||
for (u32 i = 1; i <= n; ++i) {
|
||||
for (u32 j = 1; j <= n; ++j) {
|
||||
colwise[i][j] = i * grid[i - 1][j - 1] + colwise[i][j - 1] +
|
||||
colwise[i - 1][j] - colwise[i - 1][j - 1];
|
||||
}
|
||||
}
|
||||
|
||||
for (u32 i = 1; i <= n; ++i) {
|
||||
for (u32 j = 1; j <= n; ++j) {
|
||||
rowwise[i][j] = j * grid[i - 1][j - 1] + rowwise[i][j - 1] +
|
||||
rowwise[i - 1][j] - rowwise[i - 1][j - 1];
|
||||
}
|
||||
}
|
||||
|
||||
u64 x1, y1, x2, y2;
|
||||
for (u32 i = 0; i < q; ++i) {
|
||||
cin >> x1 >> y1 >> x2 >> y2;
|
||||
|
||||
auto s =
|
||||
one[x2][y2] - one[x2][y1 - 1] - one[x1 - 1][y2] + one[x1 - 1][y1 - 1];
|
||||
auto sr = colwise[x2][y2] - colwise[x2][y1 - 1] - colwise[x1 - 1][y2] +
|
||||
colwise[x1 - 1][y1 - 1];
|
||||
auto sc = rowwise[x2][y2] - rowwise[x2][y1 - 1] - rowwise[x1 - 1][y2] +
|
||||
rowwise[x1 - 1][y1 - 1];
|
||||
|
||||
u64 w = y2 - y1 + 1;
|
||||
|
||||
u64 ans = w * (sr - (u64)x1 * s) + (sc - (u64)y1 * s) + s;
|
||||
|
||||
cout << ans << " \n"[i == q - 1];
|
||||
}
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
cin.exceptions(cin.failbit);
|
||||
|
||||
u32 tc = 1;
|
||||
cin >> tc;
|
||||
|
||||
for (u32 t = 0; t < tc; ++t) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
16
codeforces/993/io/h.in
Normal file
16
codeforces/993/io/h.in
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
2
|
||||
4 3
|
||||
1 5 2 4
|
||||
4 9 5 3
|
||||
4 5 2 3
|
||||
1 5 5 2
|
||||
1 1 4 4
|
||||
2 2 3 3
|
||||
1 2 4 3
|
||||
3 3
|
||||
1 2 3
|
||||
4 5 6
|
||||
7 8 9
|
||||
1 1 1 3
|
||||
1 3 3 3
|
||||
2 2 2 2
|
||||
5
codeforces/993/io/h.out
Normal file
5
codeforces/993/io/h.out
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
500 42 168
|
||||
14 42 5
|
||||
|
||||
[code]: 0
|
||||
[time]: 4.26412 ms
|
||||
29
codeforces/993/makefile
Normal file
29
codeforces/993/makefile
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
.PHONY: run debug clean setup init
|
||||
|
||||
VERSION ?= 20
|
||||
|
||||
SRC = $(word 2,$(MAKECMDGOALS))
|
||||
|
||||
.SILENT:
|
||||
|
||||
run:
|
||||
sh scripts/run.sh $(SRC)
|
||||
|
||||
debug:
|
||||
sh scripts/debug.sh $(SRC)
|
||||
|
||||
clean:
|
||||
rm -rf build/*
|
||||
|
||||
setup:
|
||||
test -d build || mkdir -p build
|
||||
test -d io || mkdir -p io
|
||||
test -d scripts || mkdir -p scripts
|
||||
test -f compile_flags.txt || cp $(HOME)/.config/cp-template/compile_flags.txt . && echo -std=c++$(VERSION) >>compile_flags.txt
|
||||
test -f .clangd || cp $(HOME)/.config/cp-template/.clangd . && echo -e "\t\t-std=c++$(VERSION)" >>.clangd
|
||||
|
||||
init:
|
||||
make setup
|
||||
|
||||
%:
|
||||
@:
|
||||
29
codeforces/993/scripts/debug.sh
Normal file
29
codeforces/993/scripts/debug.sh
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#!/bin/sh
|
||||
|
||||
. ./scripts/utils.sh
|
||||
|
||||
SRC="$1"
|
||||
BASE=$(basename "$SRC" .cc)
|
||||
INPUT="${BASE}.in"
|
||||
OUTPUT="${BASE}.out"
|
||||
DBG_BIN="${BASE}.debug"
|
||||
|
||||
test -d build || mkdir -p build
|
||||
test -d io || mkdir -p io
|
||||
|
||||
test -f "$INPUT" && test ! -f "io/$INPUT" && mv "$INPUT" "io/"
|
||||
test -f "$OUTPUT" && test ! -f "io/$OUTPUT" && mv "$OUTPUT" "io/"
|
||||
|
||||
test -f "io/$INPUT" || touch "io/$INPUT"
|
||||
test -f "io/$OUTPUT" || touch "io/$OUTPUT"
|
||||
|
||||
INPUT="io/$INPUT"
|
||||
OUTPUT="io/$OUTPUT"
|
||||
DBG_BIN="build/$DBG_BIN"
|
||||
|
||||
compile_source "$SRC" "$DBG_BIN" "$OUTPUT" @debug_flags.txt
|
||||
CODE=$?
|
||||
test $CODE -gt 0 && exit $CODE
|
||||
|
||||
execute_binary "$DBG_BIN" "$INPUT" "$OUTPUT"
|
||||
exit $?
|
||||
29
codeforces/993/scripts/run.sh
Normal file
29
codeforces/993/scripts/run.sh
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#!/bin/sh
|
||||
|
||||
. ./scripts/utils.sh
|
||||
|
||||
SRC="$1"
|
||||
BASE=$(basename "$SRC" .cc)
|
||||
INPUT="${BASE}.in"
|
||||
OUTPUT="${BASE}.out"
|
||||
RUN_BIN="${BASE}.run"
|
||||
|
||||
test -d build || mkdir -p build
|
||||
test -d io || mkdir -p io
|
||||
|
||||
test -f "$INPUT" && test ! -f "io/$INPUT" && mv "$INPUT" "io/"
|
||||
test -f "$OUTPUT" && test ! -f "io/$OUTPUT" && mv "$OUTPUT" "io/"
|
||||
|
||||
test -f "io/$INPUT" || touch "io/$INPUT"
|
||||
test -f "io/$OUTPUT" || touch "io/$OUTPUT"
|
||||
|
||||
INPUT="io/$INPUT"
|
||||
OUTPUT="io/$OUTPUT"
|
||||
RUN_BIN="build/$RUN_BIN"
|
||||
|
||||
compile_source "$SRC" "$RUN_BIN" "$OUTPUT" ""
|
||||
CODE=$?
|
||||
test $CODE -gt 0 && exit $CODE
|
||||
|
||||
execute_binary "$RUN_BIN" "$INPUT" "$OUTPUT"
|
||||
exit $?
|
||||
53
codeforces/993/scripts/utils.sh
Normal file
53
codeforces/993/scripts/utils.sh
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
#!/bin/sh
|
||||
|
||||
execute_binary() {
|
||||
binary="$1"
|
||||
input="$2"
|
||||
output="$3"
|
||||
|
||||
start=$(date '+%s.%N')
|
||||
timeout 2s ./"$binary" <"$input" >"$output" 2>&1
|
||||
CODE=$?
|
||||
end=$(date '+%s.%N')
|
||||
truncate -s "$(head -n 1000 "$output" | wc -c)" "$output"
|
||||
|
||||
if [ $CODE -ge 124 ]; then
|
||||
MSG=''
|
||||
case $CODE in
|
||||
124) MSG='TIMEOUT' ;;
|
||||
128) MSG='SIGILL' ;;
|
||||
130) MSG='SIGABRT' ;;
|
||||
131) MSG='SIGBUS' ;;
|
||||
136) MSG='SIGFPE' ;;
|
||||
135) MSG='SIGSEGV' ;;
|
||||
137) MSG='SIGPIPE' ;;
|
||||
139) MSG='SIGTERM' ;;
|
||||
esac
|
||||
[ $CODE -ne 124 ] && sed -i '$d' "$output"
|
||||
test -n "$MSG" && printf '\n[code]: %s (%s)' "$CODE" "$MSG" >>"$output"
|
||||
else
|
||||
printf '\n[code]: %s' "$CODE" >>"$output"
|
||||
fi
|
||||
|
||||
printf '\n[time]: %s ms' "$(awk "BEGIN {print ($end - $start) * 1000}")" >>$output
|
||||
return $CODE
|
||||
}
|
||||
|
||||
compile_source() {
|
||||
src="$1"
|
||||
bin="$2"
|
||||
output="$3"
|
||||
flags="$4"
|
||||
|
||||
test -f "$bin" && rm "$bin" || true
|
||||
g++ @compile_flags.txt $flags "$src" -o "$bin" 2>"$output"
|
||||
CODE=$?
|
||||
|
||||
if [ $CODE -gt 0 ]; then
|
||||
printf '\n[code]: %s' "$CODE" >>"$output"
|
||||
return $CODE
|
||||
else
|
||||
echo '' >"$output"
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue