lqdoj
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Help
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # Solution Sơ loại OLP MTTN 2023 (Chuyên Tin) ## B1: TEAMBUILDING Tóm tắt: Đếm số cách chia mảng $a$ thành các nhóm liên tiếp. Mỗi nhóm thỏa mãn abcxyz. --- ### Sub 1: $n \le 20$ Có $n$ người thì sẽ có $n-1$ "khoảng trống" để ta đặt/ không đặt "vách ngăn" vào. Mỗi cách đặt như vậy là một cách chia nhóm. Ví dụ: [Hình vẽ] (soon^TM) Quay lui $O(2^n)$ --- ### Sub 2: $n \le 500$ Cài chưa chuẩn ? ### Sub 3: $n \le 5000$ Đặt $f(i)$ là số cách để chia $i$ người đầu. Từ $f(i)$ ta cập nhật $f(j)$ với $j > i$. Thêm một nhóm $i+1, i+2, i+3, ..., j$. Nếu được thì $\texttt{f(j) += f(i)}$ ![](https://i.imgur.com/CuJcjTQ.png) (Nguyễn Minh Huy, A5 K37 LQĐ) --- ## B2: FRUITMARKET Tóm tắt: Hoa sẽ đi mua quả theo vòng tròn: mỗi tiệm mua $\le 1$ quả xong rồi qua tiệm tiếp theo. Dừng lại khi không đủ tiền mua quả rẻ nhất. **Bước 1:** Tính xem thử Hoa đã đi được bao nhiêu vòng trước khi $m<$ tổng? Đặt $S$ là tổng dãy $a$. Số vòng $= [m / S]$. Giả sử sau khi mua các vòng thì còn dư $m'$ tiền. ### Thuật trâu: Mô phỏng lại toàn bộ quá trình mua hàng của Hoa. ```cpp for (int i = 1; m >= Min; i++) { if (i > n) i = 1; if (m >= a[i]) { m -= a[i]; ans++; } } ``` ### Sub 1: $n = 2$ Có các giai đoạn: - Còn đủ tiền mua $2$ quả - Chỉ đủ tiền mua quả rẻ nhất - Thiếu tiền Dùng phép chia để xem mỗi giai đoạn xảy ra trong bao lâu (bao nhiêu vòng?) ### Sub 2: $a_1 \le a_2 \le ... \le a_n$ Tính mảng tiền tố (prefix-sum). Mô phỏng lại các vòng đi chợ của Hoa. Do $a$ tăng dần nên những loại quả được mua sẽ là những quả ở các quầy đầu tiên. Do đó chỉ cần TKNP để xác định là mua tới quả nào thì hết tiền, xong lại bắt đầu vòng mới. ```cpp // Credit: OLP4CT587 void sub2() { int res = 0; //prefix-sum for (int i = 1; i <= n; i++) a[i] += a[i - 1]; //trở thành tổng i số đầu tiên while (m >= a[1]) { int k = upper_bound(a + 1, a + 1 + n, m) - a - 1; //upper_bound: tìm vị trí đầu tiên > hẳn m // lại -1 đi để ra vị trí cuối cùng <= res += (m / a[k]) * k; m = m % a[k]; } cout << res; } ``` ### Sub 3: $m \le \min a\cdot 10^6$ Đáp án chắc chắn $\le 10^6$. Tuy nhiên nếu cày trâu như trên thì sẽ TLE (theo lí thuyết) vì có trường hợp quả rẻ nhất nằm ở một vị trí duy nhất, và ta phải chạy for hết $n$ phần tử mới tìm được quầy rẻ đó để mua. VD: ``` n = 1e5, m = 1e18 a[i] = 10^9 với mọi i, ngoại trừ tại vị trí i = ? thì a[i] = 1 ``` Ý tưởng: http://online.vku.udn.vn/src/88371 Dùng DSU, tính mảng $nxt(i)$ là vị trí tiếp theo trên vòng tròn mà $\le m$ (số tiền còn hiện tại) ![](https://i.imgur.com/oyWvzsG.png) ### Sub 4: ### Đơn giản Thuật toán sau mô phỏng lại thuật trâu: ![](https://i.imgur.com/fP6HJ1x.png) Code trên của: baoduong23042007 Giải thích: Vòng lặp `while` bên ngoài thực hiện rất ít lần, vì câu lệnh `m %= sum` sẽ giảm $m$ đi ít nhất $2$ lần (nếu `m > sum`). Nếu `m < sum` thì phần "cày trâu" sẽ giảm $m$ đi xuống rất bé ? ### Phức tạp (Chưa kiểm chứng được đúng sai nhưng thấy có một số thí sinh code BIT) Xét $O(n)$ thời điểm đặc biệt: ngay khi $m$ giảm xuống bé hơn giá trị lớn thứ $i$ trong dãy $a$. Quầy hàng nào đắt hơn $m$ thì ta "xóa" nó đi. Về ý tưởng thì vẫn dùng phép chia (đi thành nhiều vòng) giống subtask 1, cho tới khi $m$ bé hơn mốc tiếp theo. Vậy việc cần quan tâm là xét trong một đoạn liên tiếp sẽ có bao nhiêu số chưa bị "xóa" Có cần BIT hay không? ## B3: DISTANCE Tóm tắt: Cho cây $n$ đỉnh. Có $k$ đỉnh đặc biệt. Hỏi khoảng cách từ $u$ tới đỉnh đặc biệt gần nhất ($\neq u$) là bao nhiêu? ### Sub 1: $n \le 200$ Thuật $O(n^2):$ Tính trước k/cách giữa mọi cặp đỉnh trên cây (BFS/DFS), lưu vào mảng. Sau đó chạy `for` $n^2$ để tìm cà phê gần nhất. ### Sub 2: $n \le 10^5, k \le 50$ Với mỗi $u$, ta duyệt qua $k$ đỉnh đặc biệt, cần lấy k/cách từ $u$ tới đỉnh đó. Vậy lúc đầu cần tính trước bằng cách BFS/DFS từ mỗi một trong $k$ đỉnh. Hoặc: dùng LCA để tính (phức tạp). ĐPT: $O(nk)$ ### Sub 3 + 4: Làm chưa tối ưu la http://online.vku.udn.vn/src/89811 QHĐ trên cây. DFS 2 lần để tính hai loại khoảng cách: - từ nút con cháu cập nhật lên $u$ - từ nút tổ tiên (nằm ngoài cây gốc $u$) cập nhật cho $u$. Đặt `dp_down[u], dp_up[u]` lần lượt là k/c loại 1,2 ở trên. Khoảng cách loại 1 tính được bằng dfs thông thường. Gọi dfs để tính `dp_down` của những nút con cháu trước, sau đó gán `dp_down[u] = max(dp_down[v] + w)`. https://viblo.asia/p/quy-hoach-dong-tren-cay-LzD5d9B4KjY Khoảng cách loại 2 phải tính ngược lại một chút. Tận dụng khoảng cách loại 1, và kết quả từ các nút cha & tổ tiên ta cập nhật cho các nút con cháu. Có hai trường hợp: - `dp_up[v] = dp_up[u] + w` (từ nút tổ tiên của $u$ cập nhật cho $v$) - Từ một nhánh khác trong cây con gốc $u$, gọi là $v_2$, cập nhật cho $v$. Ta có `dp_up[v] = dp_down[v2] + w2 + w1` (từ nút $v_2$, đi theo hai cạnh để tới $u$, rồi tới $v$) Nếu nhóm biểu thức trên lại, ta thấy cần lấy $\max$ của tất cả `dp_down[.] + w[.]` của những nhánh khác $v$. #### Sub 3: Ta lưu hết vào một `multiset`, khi duyệt tới nhánh hiện tại thì xóa nó đi để tính, xong lại thêm vào. ĐPT $O(n\log)$ #### Sub 4: Cần tìm $\max$ mọi nhánh còn lại nhanh hơn. Có thể: - Hướng 1: Làm giống prefix-sum - Hướng 2: Lưu lại hai giá trị bé nhất. ## B4: CARDGAME ### $O(n^2)$ Thử hết mọi đoạn con (chạy for $l,r$), lấy tổng đoạn trừ max ### Full (idea) Giả sử $a_i$ lớn hơn mọi số trong đoạn $[l,r]$ (dùng stack/ gì đó để tìm l min, r max). Tính prefix-sum thôi: Lấy max của S từ i tới r, trừ cho min của S từ l-1 tới i-1. Segment Tree

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully