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 New
    • 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 Note Insights Versions and GitHub Sync 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
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Solution Giao lưu Tin học trẻ Mở rộng 2023 Lần 1 - Bảng C (1&2) ## Bignum Bài đơn giản nhưng cần lưu ý: - Số $0$ - Không thể nhân hết $n$ số lại rồi mới `if`. Giả sử cho test max: $n = 10^5, a = 10^{18}$ thì tích rất lớn ($10^{18n}$), do đó các phép tính nhân chạy rất chậm - Nếu dùng `C++`, để kiểm tra $ab > c$ với $a,b$ là 2 số `long long`, có thể chuyển thành phép chia. ## Đoạn đường nhàm chán ### Đề bài Đếm số đoạn con có không quá $k$ giá trị phân biệt. **Lưu ý** số $\theta$ có công dụng là cho biết đang giải subtask mấy ### Subtask 2 Để xác định một đoạn con, cần biết được hai chỉ số $l,r$. Vậy ta `for` $l,r$. Với mỗi $l$, ta có một mảng đếm phân phối để biết được giá trị nào đã được thêm vào. Khi $r$ tăng dần thì cộng dần vào mảng này. ```python= theta = int(input()) n,k = map(int, input().split()) h = list(map(int, input().split())) ans = 0 for i in range(n): dpp = [0]*(n+1) cnt = 0 for j in range(i,n): dpp[h[j]] += 1 # thêm vào 1 lần xuất hiện của h[j] if dpp[h[j]] == 1: cnt += 1 # h[j] mới được thêm lần đầu! if cnt > k: break ans += 1 print(ans) ``` ### Subtask 3: chiều cao khác nhau Số giá trị = độ dài đoạn $\rightarrow$ bao nhiêu đoạn con độ dài $\le k?$ ### Subtask 4: $k = 1$ Điều kiện $\Leftrightarrow$ đoạn con gồm các phần tử giống nhau Một số hướng: + Tính $f[i]$ là vị trí xa $i$ nhất về bên trái mà từ $f[i]$ tới $i$ có giá trị như nhau + Lấy ra các đoạn liên tiếp giống nhau & tính ### Thuật chuẩn Subtask 3,4 được dùng để vét thêm điểm nếu không nghĩ được thuật full. Từ ý tưởng của subtask 2: chạy for $j$ để tìm vị trí xa nhất có thể. Nhận thấy việc chạy như vậy là kém hiệu quả vì: khi $i$ tăng thì vị trí xa nhất có thể cũng phải tăng (vì sao?) Minh họa: ![](https://i.imgur.com/kd1zuEo.png) i chạy thì "biên giới" cũng chạy theo (vì bớt đi một số $a[i]$ nên mở ra nhiều khả năng cho những số phía sau hơn? ...) Code tham khảo: ![](https://i.imgur.com/mfGA2sq.png) ## Quý Mão 2023 ### Đề bài Đếm số đoạn con liên tiếp, các phần tử cách nhau $e$ đơn vị mà có tích là SNT. Với subtask 1 và 2, $a \le 10^3$ nên có thể kiểm tra SNT trâu. ### Subtask 1: $n \le 200, a\le 1000$ Chạy trâu, duyệt qua $O(n^2)$ cặp số $(j,k)$ và kiểm tra. Điều kiện đề bài cho tương ứng với: trong các số liên tiếp đó có **đúng một** số nguyên tố và các số còn lại đều bằng $1$ ### Subtask 2: $e = 1, a \le 1000$ Bước nhảy $e = 1 \Rightarrow$ Chỉ xét những đoạn con liên tiếp mà có đúng 1 SNT. Ta chỉ quan tâm những vị trí nào mà là số nguyên tố. Để tạo được một đoạn thỏa mãn, ta duyệt về phía bên trái & phải và thêm vào một vài số $1$ liên tiếp nhau. Đặt $l(i)=j$ là vị trí xa nhất về bên trái, mà tất cả các số từ $j$ tới $i$ đều bằng $1$. Tương tự có $r(i)$, cho bên phải. Giả sử từ vị trí $i$ có $a[i]$ là SNT, bên trái có thể chọn tối đa $L$ số $1$ (trước khi tới tận cùng mảng hoặc gặp số khác $1$), bên phải có thể chọn tối đa $R$ số. Như vậy số đoạn con thỏa mãn là $L + R + LR$. ### Subtask 3: $e$ không quan trọng vì cách tính hoàn toàn như trên. Phần này chỉ đòi hỏi phải sàng nguyên tố trước. ## Lướt sóng ### Subtask 1: $n \le 20$ Đệ quy quay lui, mỗi đợt có thể chọn/ không chọn. ĐPT $O(2^n)$ hoặc $O(n.2^n)$ ### Subtask 2: $n \le 1000$ QHĐ: bài toán đếm/ tối ưu Thử tiếp cận bằng cách đặt $f(i)$ : xét trong $i$ số đầu tiên, chọn được nhiều nhất là bao nhiêu số? Tuy nhiên không viết được công thức (vì không quản lí được điều kiện tổng tạo được luôn $\ge 0$) Vì cần biết tổng đang là bao nhiêu nên có thể đặt như sau: $f(i,s) = x$ trong $i$ đợt đầu, tổng lợi nhuận đang là $s$ thì chọn được nhiều nhất là $x$. Vì tổng quá lớn nên có thể đổi cách gọi hàm QHĐ thành như sau: $f(i,x) = s$ giả sử trong $i$ số đầu tiên, chọn ra $x$ số (mà thỏa điều kiện) thì tổng cuối cùng lớn nhất là bao nhiêu? ### Subtask 3: $n \le 10^5$ Cứ "vào lệnh" liên tục, lúc nào âm tiền (tổng âm) thì quay ngược lại quá khứ và hủy lệnh trước đó (số bé nhất). Một bài tương tự (gần đây), các bạn có thể tham khảo lời giải trên Blog CF https://codeforces.com/contest/1779/submission/187766175 ### Lưu ý: Vì chưa kịp viết, và mình mặc định những bạn hướng tới việc giải được các bài này khá giỏi nên mình viết khá gọn. ## Sắp xếp Bạn cần làm subtask 1 trước. Từ đó sẽ thấy các thao tác tìm vị trí có thể tối ưu được bằng segment tree ## Trà sữa Dùng thuật toán Tarjan để tìm cầu, từ đó nén thành một cây. Nhận xét: Đáp án của bài toán trên đồ thị dạng cây là trọng số lớn nhất trong $n$ đỉnh. Có nhiều cách để định chiều cạnh, trong đó một cách đơn giản là sử dụng các cạnh của dfs-tree (theo đúng thứ tự duyệt dfs)

    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