RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
USACO0658

The Best Subsequence

Gold II 골드 II
난이도
2s
시간 제한
256MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

Farmer John has a binary string of length \(N\) \((1 \leq N \leq 10^9)\), initially
all zeros.

He will first perform \(M\) (\(1 \leq M \leq 2 \cdot 10^5\)) updates on the string,
in order. Each update flips every character from \(l\) to \(r\). Specifically,
flipping a character changes it from \(0\) to \(1\), or vice versa.

Then, he asks you \(Q\) (\(1 \leq Q \leq 2 \cdot 10^5\)) queries. For each query, he
asks you to output the lexicographically greatest subsequence of length \(k\)
comprised of characters from the substring from \(l\) to \(r\). If your answer is a
binary string \(s_1s_2 \dots s_k\), then output
\(\sum_{i=0}^{k-1} 2^i \cdot s_{k-i}\) (that is, its value when interpreted as a
binary number) modulo \(10^9+7\).

A subsequence is a string that can be derived from another string by deleting
some or no characters without changing the order of the remaining characters.

Recall that string \(A\) is lexicographically greater than string \(B\) of equal
length if and only if at the first position \(i\), if it exists, where
\(A_i \neq B_i\), we have \(A_i > B_i\).

Problem credits: Chongtian Ma

제약

SCORING

  • Input 4: \(N \leq 10, Q \leq 1000\)
  • Input 5: \(M \leq 10\)
  • Inputs 6-7: \(N, Q \leq 1000\)
  • Inputs 8-12: \(N \leq 2 \cdot 10^5\)
  • Inputs 13-20: No additional constraints.

Problem credits: Chongtian Ma

입력 형식

The first line contains \(N\), \(M\), and \(Q\).

The next \(M\) lines contain two integers, \(l\) and \(r\) (\(1 \leq l \leq r \leq N\))
— the endpoints of each update.

The next \(Q\) lines contain three integers, \(l\), \(r\), and \(k\)
(\(1 \leq l \leq r \leq N, 1 \leq k \leq r - l + 1\)) — the endpoints of each
query and the length of the subsequence.

출력 형식

Output \(Q\) lines. The \(i\)th line should contain the answer for the \(i\)th query.

예제 1
입력
5 3 9
1 5
2 4
3 3
1 5 5
1 5 4
1 5 3
1 5 2
1 5 1
2 5 4
2 5 3
2 5 2
2 5 1
출력
21
13
7
3
1
5
5
3
1
설명

After performing the \(M\) operations, the string is \(10101\).

For the first query, there is only one subsequence of length \(5\), \(10101\), which
is interpreted as
\(1 \cdot 2^4 + 0 \cdot 2^3 + 1 \cdot 2^2 + 0 \cdot 2^1 + 1 \cdot 2^0 = 21\).

For the second query, there are \(5\) unique subsequences of length \(4\): \(0101\),
\(1101\), \(1001\), \(1011\), \(1010\). The lexicographically largest subsequence is
\(1101\), which is interpreted as
\(1 \cdot 2^3 + 1 \cdot 2^2 + 0 \cdot 2^1 + 1\cdot 2^0 = 13\).

For the third query, the lexicographically largest sequence is \(111\), which is
interpreted as \(7\).

예제 2
입력
9 1 1
7 9
1 8 8
출력
3
예제 3
입력
30 1 1
1 30
1 30 30
출력
73741816
설명

Make sure to output the answer modulo \(10^9+7\).

문제 정보

riseoj 작성

출처 올림피아드 > USACO > 2024-2025 > February > Gold

태그

평가 및 의견

The Best Subsequence

개요
출제자 난이도 Gold II 골드 II 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

The Best Subsequence

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8