luogu#P5141. 列队

列队

Background

This problem is the strengthened version. For the weakened version, please refer to NOIP2017NOIP2017 DAY2DAY2 T3T3.

Okay, just to scare you a bit.

Problem Description

Some time ago, kk-xiao-ll joined the military training for Grade 10 at CTYZCTYZ. As everyone knows, during military training you need to stand in a square formation.

In the team where kk-xiao-ll is, there were originally 2N2*N people (weak ones and top ones), but now only a few top ones including kk-xiao-ll and some weak ones are left.

Top one dwqdwq: Instructor, I still haven't finished debugging the last problem of this year's IOIIOI. I'll go back first and solve it.

Instructor: OK, leave approved. If you finish debugging in ten minutes, go back and rest first.

Weak one yzyz: Instructor, I haven't finished the hard problems in today's task plan. I want to go back and do them.

Instructor: Even if you go back now you still can't debug it. Stand properly. Stop trying to slack off.

kk-xiao-ll is a boy who loves learning. Now he finds that there are only two columns left on the playground. Originally, both columns had length NN, but now they are incomplete. The weak ones stand in the first column, and the top ones stand in the second column. Also, if there is a top one in a row, their presence will make the weak ones in the adjacent position not dare to stand there.

Even so, the remaining top ones are still stronger than the weak ones (obviously).

In CTYZCTYZ, the fighting value of one column is defined as

Fight=i=0n1pi2iFight=\sum_{i=0}^{n-1} p_{i}*2^{i}

where ii is the row index starting from 00, and pi=1/0p_{i}=1/0 indicates whether there is a person in this row.

Now kk-xiao-ll already knows the current standing situation of the top-one column. He wants to ask you: how many possible standing ways can the weak ones have?

However, kk-xiao-ll thinks this is too easy. He now has MM queries. Each query gives you a weak-ones fighting value range [a,b][a,b] and a kk, meaning he wants to know: among the weak-ones standing ways whose fighting value is within [a,b][a,b], what is the fighting value of the kk-th largest one. If the total number of standing ways is less than kk, then output POORPOOR AFO!AFO!.

Input Format

The first line contains two integers N,MN,M, meaning the queue has NN rows, and kk-xiao-ll has MM queries.

The second line is a 0101 string, representing the standing way of the top ones.

The next MM lines each contain three numbers ai,bi,kia_{i},b_{i},k_{i}, representing the queries of kk-xiao-ll.

Output Format

Output MM lines, each being the answer. kk-xiao-ll is very kind and allows you to output the fighting value modulo 2003110220031102.

5 5
0 1 0 1 0 
0 4 5
0 3 4
0 0 1
0 1 2
4 4 1

POOR AFO!
POOR AFO!
0
0
4

10 5
1 1 0 1 1 0 0 1 0 0 
0 56 7
30 126 7
62 116 5
20 100 1
8 108 1

POOR AFO!
POOR AFO!
POOR AFO!
100
100

5 1
0 0 0 0 1
0 999 1
15

Hint

For 50%50\% of the data, N<=20,M<=50N<=20,M<=50.

For 100%100\% of the data, N<=62,M<=500000N<=62,M<=500000.

The time limit is very loose, so feel free to enjoy it.

Translated by ChatGPT 5