18 Commits

Author SHA1 Message Date
unlockable
5b6faf4409 Only MLE 2023-11-20 19:37:30 +08:00
unlockable
615133f12a MLE and WA. 2023-11-20 19:19:45 +08:00
unlockable
266b237108 MLE and WA 2023-11-13 19:55:54 +08:00
unlockable
6af94e27b0 90. 2023-11-13 19:55:54 +08:00
unlockable
77eb4765be Use long long. 2023-11-13 19:55:54 +08:00
unlockable
c07330c8af Read in data before anything started. 2023-11-05 16:33:25 +08:00
unlockable
b7b8af4811 Use long long. 2023-11-05 15:13:10 +08:00
unlockable
cf1e94a5d1 Bigger ans. 2023-11-05 15:03:44 +08:00
unlockable
744a773e95 Better comment. 2023-11-05 14:19:57 +08:00
unlockable
1d3a916eb5 开略大的数组。 2023-11-05 13:44:49 +08:00
unlockable
3aabda4b43 只有60分。 2023-11-05 13:36:11 +08:00
unlockable
2642acd00a Output 0 when no path possible. 2023-11-05 11:03:05 +08:00
unlockable
32bd7e91fd 1, 2, 3, 4, 7AC. 2023-11-05 10:52:27 +08:00
unlockable
a370d5a723 Example not correct. 2023-11-05 01:24:20 +08:00
unlockable
a91c9637e8 Complete comment. 2023-10-24 11:13:30 +08:00
unlockable
4726deb30c AC! 2023-10-22 13:25:02 +08:00
unlockable
03e0e30a95 Can't deal with same numbers in a row. 2023-10-21 22:36:12 +08:00
unlockable
8a44704bdd AC! 2023-10-08 00:28:37 +08:00
6 changed files with 369 additions and 103 deletions

View File

@@ -77,7 +77,7 @@ BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 80
ColumnLimit: 100
CommentPragmas: '^ IWYU pragma:'
QualifierAlignment: Leave
CompactNamespaces: false

View File

@@ -1,121 +1,47 @@
#include <stdio.h>
template <class E> class Node {
private:
E content;
Node<E> *next;
public:
Node(const E &_content) : content(_content), next(this){};
Node(const E &_content, Node<E> *nextPtr)
: content(_content), next(nextPtr){};
void setNext(Node<E> *_ptr) {
this->next = _ptr;
}
E &getContent() {
return this->content;
}
Node<E> *getNextPtr() {
return this->next;
}
struct Node{
int prev, next;
};
template <class E> class Iterator {
private:
Node<E> *current;
public:
Iterator(Node<E> *start) : current(start){};
E &peekNext() {
return this->current->getNextPtr()->getContent();
}
void next() {
this->current = this->current->getNextPtr();
}
E &peek() {
return this->current->getContent();
}
Node<E> *peekNode() {
return this->current;
}
void insertHere(const E &newItem) {
this->current->setNext(
new Node<E>(newItem, this->current->getNextPtr()));
}
};
template <class E> class List {
private:
// int _length;
Node<E> head;
public:
List(const E &dummyValue)
: head(Node<E>(dummyValue)){
// this->_length = 0;
};
void insert(const E &target, const E &newItem) {
Iterator<E> iter = Iterator<E>(&this->head);
// Remember to add a loop to stop at length!!;
while (iter.peek() != target) {
iter.next();
}
iter.insertHere(newItem);
// this->_length++;
}
void remove(const E &target) {
Iterator<E> iter = Iterator<E>(&this->head);
while (iter.peekNext() != target) {
iter.next();
}
Node<E> *toBeDeleted = iter.peekNode()->getNextPtr();
iter.peekNode()->setNext(toBeDeleted->getNextPtr());
delete toBeDeleted;
// this->_length--;
}
Iterator<E> iterate() {
return Iterator<E>(&this->head);
}
};
Node map[100000];
int main() {
List<int> aList(0);
aList.insert(0, 1);
map[0].prev = 1;
map[0].next = 1;
map[1].prev = 0;
map[1].next = 0;
int n;
int cmd, x, y;
scanf("%d", &n);
while (n) {
scanf("%d %d", &cmd, &x);
switch (cmd) {
case 1: {
scanf("%d", &y);
aList.insert(x, y);
break;
}
case 2: {
Iterator<int> iter = aList.iterate();
while (iter.peek() != x) {
iter.next();
switch(cmd) {
case 1: {
scanf("%d", &y);
map[y].prev = x;
map[y].next = map[x].next;
map[x].next = y;
map[map[y].next].prev = y;
break;
}
case 2: {
printf("%d\n", map[x].next);
break;
}
case 3: {
map[map[x].prev].next = map[x].next;
map[map[x].next].prev = map[x].prev;
break;
}
printf("%d\n", iter.peekNext());
break;
}
case 3: {
aList.remove(x);
}
}
n--;
}
Iterator<int> iter = aList.iterate();
iter.next();
while (true) {
int content = iter.peek();
if (content == 0) {
break;
}
printf("%d\n", content);
iter.next();
int cur = map[0].next;
while (cur != 0) {
printf("%d\n", cur);
cur = map[cur].next;
}
return 0;
}

48
2023203/main.cpp Normal file
View File

@@ -0,0 +1,48 @@
#include <stdio.h>
// 创建一个栈,拿到一个数,与栈顶比较,如果比栈顶小,压栈(正在波峰向波谷下降)
// 比栈顶大,弹栈并计数;和栈顶相同,计数并且压入。
struct NumberNode {
int data;
int count;
};
long long totalPairs;
NumberNode powers[500010];
int main() {
int len = 1;
int N;
int input;
totalPairs = 0;
powers[0].data = 0;
powers[0].count = 0;
scanf("%d", &N);
scanf("%d", &powers[1].data);
powers[1].count = 1;
N--;
for (int i = 0; i < N; i++) {
scanf("%d", &input);
while (len != 0 && powers[len].data < input) {
totalPairs += powers[len].count;
len--;
}
if (len == 0 ) {
powers[1].data = input;
powers[1].count = 1;
len = 1;
} else {
if (powers[len].data == input) {
totalPairs += powers[len].count + (len > 1);
powers[len].count++;
}
else {
totalPairs += 1;
powers[++len] = NumberNode {input, 1};
}
}
}
printf("%lld", totalPairs);
return 0;
}

164
2023204/main.cpp Normal file
View File

@@ -0,0 +1,164 @@
#include <stdio.h>
#define DEAD false
#define ALIVE true
// 'Natural count' is the name of the node when all the nodes in the tree is
// alive. xxx_num denotes the count as the question described.
// SEE ALSO BRANCH 04_02 WITH A CORRECT IMPLEMENTATION
int ans[200] = {0};
long long dead_nodes_num[105] = {0};
int total_dead_nodes = 0;
long long target_nodes_num[105] = {0};
int total_target_nodes = 0;
struct SeveralContinuedDeadNode {
bool status;
long long length; // Caution that when status == dead and length == 1, the node itself is alive.
};
struct SearchResult {
int next_ans_pos; // pos in the ans[] array.
long long count_in_father_line; // natural count.
};
SearchResult find_node(long long target, long long start_num, int next_dead_node_num_ptr,
SeveralContinuedDeadNode *upper_line, long long upper_line_segment_count,
int layer) {
long long spawned_node_max_num = start_num - 1;
long long segment_count = upper_line_segment_count;
SeveralContinuedDeadNode current_line_node[200] = {0};
long long current_line_len = 0;
bool all_dead = true;
// Spawing all the nodes in current line
for (int upper_line_iter = 0; upper_line_iter < upper_line_segment_count; upper_line_iter++) {
if (upper_line[upper_line_iter].status == DEAD) {
current_line_node[current_line_len] = upper_line[upper_line_iter];
current_line_node[current_line_len].length *= 2;
current_line_len++;
}
else {
all_dead = false;
long long total_spawned_after =
spawned_node_max_num + upper_line[upper_line_iter].length * 2;
while (dead_nodes_num[next_dead_node_num_ptr] <= total_spawned_after &&
next_dead_node_num_ptr < total_dead_nodes) {
if (dead_nodes_num[next_dead_node_num_ptr] - spawned_node_max_num > 1) {
current_line_node[current_line_len] = SeveralContinuedDeadNode{
ALIVE, dead_nodes_num[next_dead_node_num_ptr] - spawned_node_max_num - 1};
current_line_len++; // things before this new dead node
}
current_line_node[current_line_len] =
SeveralContinuedDeadNode{DEAD, 1}; // this new dead node
current_line_len++;
spawned_node_max_num = dead_nodes_num[next_dead_node_num_ptr]; // we now spawned to
// this dead node.
next_dead_node_num_ptr++;
}
if (spawned_node_max_num < total_spawned_after) {
current_line_node[current_line_len] =
SeveralContinuedDeadNode{ALIVE, total_spawned_after - spawned_node_max_num};
current_line_len++;
}
spawned_node_max_num = total_spawned_after;
}
}
if (all_dead) {
return SearchResult{1, -1};
}
if (target <= spawned_node_max_num) {
ans[0] = target;
long long natural_pos = -1, num = start_num - 1;
for (int i = 0; i < current_line_len; i++) {
if (current_line_node[i].status == DEAD) {
natural_pos += current_line_node[i].length;
num += (current_line_node[i].length == 1);
if (num == target) {
return SearchResult{1, natural_pos / 2};
}
continue;
}
// Now deal with alive nodes
if (num + current_line_node[i].length < target) {
natural_pos += current_line_node[i].length;
num += current_line_node[i].length;
}
else {
// if we made it here, then the target > num + current_line_node[i].length
return SearchResult{1, (natural_pos + target - num) / 2};
}
}
return SearchResult{1, -1};
}
else {
SearchResult current_line_pos =
find_node(target, spawned_node_max_num + 1, next_dead_node_num_ptr, current_line_node,
current_line_len, layer + 1);
if (current_line_pos.count_in_father_line < 0) {
// The path does not exist.
return SearchResult{1, -1};
}
long long natural_count = -1, num = start_num - 1;
for (int i = 0; i < current_line_len; i++) {
natural_count += current_line_node[i].length;
if (current_line_node[i].status == ALIVE || current_line_node[i].length == 1) {
num += current_line_node[i].length;
}
if (natural_count >= current_line_pos.count_in_father_line) {
num -= natural_count - current_line_pos.count_in_father_line;
ans[current_line_pos.next_ans_pos++] = num;
break;
}
}
return SearchResult{current_line_pos.next_ans_pos,
current_line_pos.count_in_father_line / 2};
}
}
int main() {
scanf("%d %d", &total_dead_nodes, &total_target_nodes);
for (int i = 0; i < total_dead_nodes; i++) {
scanf("%lld", &dead_nodes_num[i]);
}
for (int i = 0; i < total_target_nodes; i++) {
scanf("%lld", &target_nodes_num[i]);
}
if (dead_nodes_num[0] == 1) {
for (int i = 0; i < total_target_nodes; i++) {
if (target_nodes_num[i] == 1) {
printf("1\n");
continue;
}
else {
printf("0\n");
}
}
return 0;
}
else {
SeveralContinuedDeadNode firstline = SeveralContinuedDeadNode{ALIVE, 1};
for (int i = 0; i < total_target_nodes; i++) {
SearchResult result = find_node(target_nodes_num[i], 2, 0, &firstline, 1, 2);
if (result.count_in_father_line == -1) {
printf("0\n");
}
else {
printf("1 ");
for (int j = result.next_ans_pos - 1; j >= 0; j--) {
printf("%lld ", ans[j]);
}
printf("\n");
}
}
}
return 0;
}

124
2023205/main.cpp Normal file
View File

@@ -0,0 +1,124 @@
#include <stdio.h>
// 并查集。并查集只关注双向连通性。
struct Edge {
int next;
unsigned short end;
bool used_in_dfs;
};
Edge edges[1050000];
char nodes_visited[65540];
int head[65540], len;
int add_edge(int start, int terminal) {
edges[++len].end = terminal;
edges[len].next = head[start];
head[start] = len;
return 0;
}
int dfs(int start) {
if (nodes_visited[start] >= 1) {
// nodes_visited[start] = 2;
return 0;
}
nodes_visited[start] = 1;
for (int j = head[start]; j != 0; j = edges[j].next) {
edges[j].used_in_dfs = dfs(edges[j].end);
}
return 1;
}
int dfs_with_dead_edge(int start, int dead_edge_start, int dead_edge_end) {
if (nodes_visited[start] >= 1) {
return 0;
}
nodes_visited[start] = 1;
if (start == dead_edge_start) {
for (int j = head[start]; j != 0; j = edges[j].next) {
if (edges[j].end == dead_edge_end) {
continue;
}
dfs_with_dead_edge(edges[j].end, dead_edge_start, dead_edge_end);
}
return 0;
}
for (int j = head[start]; j != 0; j = edges[j].next) {
dfs_with_dead_edge(edges[j].end, dead_edge_start, dead_edge_end);
}
return 0;
}
int main() {
int N, M;
scanf("%d %d", &N, &M);
for (int start = 0; start < N; start++) {
int edge_count;
scanf("%d", &edge_count);
for (int j = 0; j < edge_count; j++) {
int terminal;
scanf("%d", &terminal);
add_edge(start, terminal);
}
}
dfs(0);
for (int i = 0; i < N; i++) {
if (nodes_visited[i] < 1) {
// Not connected!
for (int j = 0; j <= M; j++) {
printf("0\n");
}
return 0;
}
}
printf("1\n");
// for (int i = 0; i < M; i++) {
// int start, end;
// scanf("%d %d", &start, &end);
// if (nodes_visited[end] == 2) {
// printf("1\n");
// }
// else {
// printf("0\n");
// }
// }
for (int i = 0; i < M; i++) {
int start, end;
scanf("%d %d", &start, &end);
for (int j = head[start]; j != 0; j = edges[j].next) {
if (edges[j].end == end) {
if (edges[j].used_in_dfs) {
for (int k = 0; k < N; k++) {
nodes_visited[k] = 0;
}
dfs_with_dead_edge(0, start, end);
bool connected = true;
for (int k = 0; k < N; k++) {
if (nodes_visited[k] < 1) {
printf("0\n");
connected = false;
break;
}
}
if (connected) {
printf("1\n");
}
}
else {
printf("1\n");
}
break;
}
}
}
return 0;
}

4
2023205/testdat.txt Normal file
View File

@@ -0,0 +1,4 @@
4 2 2 1 2 2 2 3 0 1 0 0 1 0 2
4 1 1 1 2 2 3 2 1 3 2 1 2 0 1