diff --git a/CMakeLists.txt b/CMakeLists.txt index 62c0f28..ebc1fac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,8 +2,8 @@ cmake_minimum_required(VERSION 3.15) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) add_compile_options(-Wall) -# add_compile_options(-fsanitize=address,pointer-compare,pointer-subtract,undefined -fno-omit-frame-pointer) -# add_link_options(-fsanitize=address,pointer-compare,pointer-subtract,undefined -fno-omit-frame-pointer) +add_compile_options(-fsanitize=address,pointer-compare,pointer-subtract,undefined -fno-omit-frame-pointer) +add_link_options(-fsanitize=address,pointer-compare,pointer-subtract,undefined -fno-omit-frame-pointer) include_directories(${CMAKE_CURRENT_LIST_DIR}/include) set(CMAKE_CXX_STANDARD 26) diff --git a/src/11/16/yacs1135.cpp b/src/11/16/yacs1135.cpp new file mode 100644 index 0000000..3b4e964 --- /dev/null +++ b/src/11/16/yacs1135.cpp @@ -0,0 +1,28 @@ +#include +#include +#include +using ll = int64_t; +const ll maxn=1e6+7; +ll a[maxn],ans; +int main(){ + ll n; + std::cin>>n; + for(ll i=1;i<=n;i++){ + std::cin>>a[i]; + } + ll l=1,r=n; + while(la[r]){ + a[r-1]+=a[r]; + ans++; + r--; + }else{ + l++,r--; + } + } + std::cout< +#include +#include +#include +using ll = int64_t; + +ll a[3]; + +static inline ll check(ll n){ + if(n<0)return false; + for(ll i=0;i<3;i++){ + if(a[i]>a[i]; + std::cout< +#include +#include +#include +using ll = int64_t; + +ll n,nmax,ans; + +int main(){ + std::iostream::sync_with_stdio(false); + std::cin.tie(nullptr); + + std::cin>>n; + for(ll i=1;i<=n;i++){ + ll tmp; + std::cin>>tmp; + nmax=std::max(nmax,tmp); + if(nmax<=i){ + ans++; + } + } + std::cout< +#include +#include +#include +using namespace std; + +struct Node { + int val, idx; + Node *left, *right; + Node(int v, int i) : val(v), idx(i), left(nullptr), right(nullptr) {} +}; + +int main() { + int n, k; + cin >> n >> k; + vector a(n + 1); + vector nodes(n + 1); + + for (int i = 1; i <= n; i++) { + cin >> a[i]; + nodes[i] = new Node(a[i], i); + } + + // 建立双向链表 + for (int i = 1; i <= n; i++) { + if (i > 1) nodes[i]->left = nodes[i - 1]; + if (i < n) nodes[i]->right = nodes[i + 1]; + } + + // 最大堆,按值排序 + auto cmp = [](Node* x, Node* y) { return x->val < y->val; }; + priority_queue, decltype(cmp)> pq(cmp); + for (int i = 1; i <= n; i++) { + pq.push(nodes[i]); + } + + vector team(n + 1, 0); // 0 未分配 + int ct = 1; // 当前队伍 + + while (!pq.empty()) { + Node* cur = pq.top(); + pq.pop(); + if (team[cur->idx] != 0) continue; // 已分配 + + // 标记当前节点 + vector tr; + tr.push_back(cur); + + // 向左扩展 k 个 + Node* l = cur->left; + for (int i = 0; i < k && l != nullptr; i++) { + tr.push_back(l); + l = l->left; + } + + // 向右扩展 k 个 + Node* r = cur->right; + for (int i = 0; i < k && r != nullptr; i++) { + tr.push_back(r); + r = r->right; + } + + // 标记这些节点 + for (Node* node : tr) { + if (team[node->idx] == 0) { + team[node->idx] = ct; + } + } + + // 从链表中删除这些节点 + // 找到删除区间的最左和最右节点 + Node* lb = tr.back()->left; + Node* rb = tr.back()->right; + for (Node* node : tr) { + if (node->left) lb = node->left; + if (node->right) rb = node->right; + } + + if (lb) lb->right = rb; + if (rb) rb->left = lb; + + // 切换队伍 + ct = 3 - ct; // 1 -> 2, 2 -> 1 + } + + for (int i = 1; i <= n; i++) { + cout << team[i]; + if (i < n) cout << " "; + } + cout << "\n"; +} \ No newline at end of file