#P7723. [Ynoi2007] TB5x
[Ynoi2007] TB5x
Problem Description
This is an interactive problem.
Initially, there are points on a 2D plane. Each point has a weight , with .
There are operations in total. The operations are numbered from to and are executed in increasing order of the index.
Operation number provides , satisfying and .
The grid coordinate of a point is defined as .
For each operation, perform the following steps in order:
- Query the sum of the weights of points whose grid coordinate is , and record it in .
- For each point whose grid coordinate is , apply the modification .
- The coordinates of all points change simultaneously. For a point whose grid coordinate is , its coordinate changes from to . Where ,,。 ,,。 are all arrays, and their indices correspond to the operation index.
Here, belongs to an abstract data type , and belongs to an abstract data type .
On , an abstract operation is defined.
On , an abstract operation is defined.
On , an abstract operation is defined.
is a special element in , called the identity element.
is a special element in , called the identity element.
These operations satisfy the following properties:
For any , we have , , .
For any , we have , .
For any and , we have , , , .
Each or operation has a certain cost. Specifically, when computing or , if both are not or , then the cost is , otherwise the cost is . You must ensure every answer is correct, and the total cost must not exceed the cost limit of the current subtask.
Implementation Details
The header file defines the data type Data () and Operation (). You may use the following defined member functions to operate on values of type Data and Operation:
void Data::add_eq(const Data &a)
w.add_eq(a) computes and stores the result in . The cost of each call is when both are not identity elements, otherwise .
void Data::add(const Data &a,const Data &b)
w.add(a,b) computes and stores the result in . The cost of each call is when both are not identity elements, otherwise .
void Data::clr()
w.clr() stores in . The cost of each call is .
bool Data::empty()const
w.empty() checks whether is . If yes, it returns , otherwise it returns . The cost of each call is .
void Operation::apply(Data &a)const
w.apply(a) computes and stores the result in . The cost of each call is when both are not identity elements, otherwise .
void Operation::apply(Operation &u)const
w.apply(u) computes and stores the result in . The cost of each call is when both are not identity elements, otherwise .
void Operation::clr()
w.clr() stores in . The cost of each call is .
bool Operation::empty()const
w.empty() checks whether is . If yes, it returns , otherwise it returns . The cost of each call is .
In addition, you may use the assignment operator, copy constructor, or default constructor for Data or Operation. Using Data as an example:
w=u copies into . The cost of each call is .
Data w(u); or Data w=u; copies into the newly defined . The cost of each call is .
Data w; stores in the newly defined . The cost is .
Operation w; stores in the newly defined . The cost is .
Other than the operations on Data or Operation described above, any other operations may be treated as an attempt to attack the judging system.
Both sizeof(Data) and sizeof(Operation) are at most . In addition, the interactive library also needs no more than 64MB of memory. The time and memory limits include the time and memory used by the interactive library. Using only assignment, constructors, apply, and add is enough to write a correct program. Other functions may provide convenience.
You need to implement the following function:
void solve(
const int n,
const int m,
const int p[],
const Data d[],
const int x1[],
const int x2[],
const int y1[],
const int y2[],
const Operation o[][3][3],
Data ans[][3][3])
- : the number of points.
- : the number of operations.
- : represents the coordinate of each point, .
- : represents the initial weight of each point, .
- : represent the input of each operation. You need to store the corresponding answers into , .
For your convenience, a template is provided here. Please complete the following code:
/* BEGIN HEADER: */
class Data {
friend class Operation;
friend int main();
private:
unsigned int x, sz, T, flag;
void read();
void print() const;
public:
Data() { clr(); }
void add_eq(const Data &a);
void add(const Data &a, const Data &b);
void clr();
bool empty() const;
};
class Operation {
friend int main();
private:
unsigned int a, b, L, R, flag;
void read();
public:
Operation() { clr(); }
void apply(Data &w) const;
void apply(Operation &w) const;
void clr();
bool empty() const;
};
void solve(const int n, const int m, const int p[], const Data d[],
const int x1[], const int x2[], const int y1[], const int y2[],
const Operation o[][3][3], Data ans[][3][3]);
/* END HEADER. */
#include <bits/stdc++.h>
void solve(const int n, const int m, const int p[], const Data d[],
const int x1[], const int x2[], const int y1[], const int y2[],
const Operation o[][3][3], Data ans[][3][3]) {
// complete this
}
Because Luogu’s interactive method is somewhat unusual, when submitting you need to copy your local code here, put it inside this solve function, and submit it together with the previous HEADER. Do not include the header file "data.h" when submitting.
When writing the program locally, you should use #include"data.h", and replace it with the template in the statement when submitting.
Input Format
The provided interactive library reads the input data in the following format:
- Line 1: .
- Next lines: ( is represented by two integers).
- Line : .
- Next lines: ( is represented by integers).
Elements in are matrices, and elements in are matrices. The entries of the matrices are integers modulo .
corresponds to matrix addition, and corresponds to matrix multiplication. You can refer to the implementation of the provided interactive library for details.
In the actual judging environment, the input/output format and the definitions of , etc. may be different.
Output Format
The provided interactive library prints your answers in the following format:
- For each query, output lines. Lines each contain two integers, which represent, in order, $ans[0][0],ans[0][1],ans[0][2],ans[1][0],ans[1][1],ans[1][2],ans[2][0],ans[2][1],ans[2][2]$ for this query. The other lines are empty lines.
- Print the total cost to stderr, and print a warning when the total cost exceeds the cost limit.
4
1 1 1
2 10 5
0 6 9
3 10 4
2
2 3 1 3 10 10 11 11 10 5 7 3 2 3 6 3 2 2 8 2 3 7 2 4 7 11 8 6 9 5 3 7 11 10 10 8 8 5 5 7
1 2 1 2 2 3 6 11 1 1 5 11 5 2 8 6 1 6 9 2 7 11 3 6 9 10 8 2 9 2 9 8 2 11 3 9 4 11 2 5
0 0
11 6
0 0
6 9
0 0
0 0
0 0
0 0
10 4
0 0
0 0
15 10
0 0
0 0
125 85
30 66
100 78
0 0
10
3 5 8
1 4 6
6 8 10
9 7 5
7 6 2
4 9 1
8 8 5
0 3 5
2 6 2
5 10 3
10
4 8 8 9 5 8 3 6 7 7 10 11 10 9 10 3 5 11 3 4 10 3 8 1 3 8 4 11 3 11 5 6 2 5 11 9 6 6 2 1
4 6 5 6 1 2 1 7 10 7 9 11 11 10 10 5 3 2 2 8 2 1 6 1 9 6 6 5 9 4 6 7 2 7 5 4 3 8 1 6
1 5 6 9 7 3 9 2 5 3 2 10 6 11 5 10 5 9 8 5 11 3 3 5 5 10 2 6 2 5 8 4 5 6 10 2 10 11 1 7
3 4 3 9 9 7 1 3 8 4 2 10 5 8 11 3 4 2 1 7 3 9 8 5 4 4 6 6 8 11 11 1 4 7 2 3 2 2 3 10
6 9 2 7 4 6 1 5 6 7 2 4 2 3 11 10 1 10 1 4 10 6 8 3 3 8 1 1 11 2 8 5 5 9 4 11 5 5 9 8
5 7 5 8 10 11 9 8 10 4 1 7 7 1 5 2 10 6 4 5 4 2 1 10 1 3 5 11 1 6 2 1 6 1 6 10 11 10 1 8
3 6 1 6 10 11 9 3 7 3 9 6 1 9 11 6 7 6 3 9 4 11 4 7 2 4 5 5 5 3 4 11 3 4 4 4 6 4 1 9
6 8 2 6 11 5 7 6 6 5 7 5 9 10 6 11 4 4 2 7 2 11 4 9 3 8 7 9 3 3 5 10 2 9 9 4 7 9 7 11
2 5 1 4 5 6 7 1 2 1 1 9 6 10 6 6 1 9 5 10 7 1 8 10 1 4 4 3 9 11 11 6 9 6 8 2 8 10 11 7
6 7 3 6 11 11 11 3 6 6 9 7 6 7 2 5 3 1 8 8 1 9 4 10 9 11 6 4 2 11 10 8 3 6 6 5 11 3 11 8
17 24
0 0
7 5
18 8
8 5
0 0
16 5
0 0
0 0
157 111
0 0
235 169
40 42
63 68
0 0
126 60
0 0
147 95
215 530
0 0
0 0
2324 2024
2479 1783
0 0
1578 1592
837 509
194 446
0 0
7116 10231
7239 9388
4607 8460
0 0
0 0
6944 6628
64844 45048
0 0
72300 52348
265311 254999
50596 23640
0 0
279180 126900
244936 114292
35348 63827
0 0
0 0
172112 792956
2447373 1106786
929486 443832
1119770 935959
0 0
0 0
1649144 359228
0 0
3553200 2614140
0 0
6950234 5535094
22444890 7998435
0 0
10443636 7892656
71682584 26662760
8776334 5075523
11841632 7740868
0 0
0 0
134875573 343366288
91300520 125610782
59108239 90936089
21697728 43262120
0 0
228318480 448464600
0 0
128593760 97023136
0 0
0 0
2054901740 1978497310
0 0
72853820 66252472
1991063770 2020209575
600177312 754769101
3803713784 3298681920
1004356824 1001672808
3063260331 3299980482
4100473464 1966207784
3031825976 3091919392
0 0
325795536 455181888
0 0
2133373140 3095093880
3643561634 2339855333
576229212 1245355280
Hint
Idea: ccz181078, Solution: ccz181078, Code: ccz181078, Data: ccz181078.
Special thanks: w33z8kqrqk8zzzx33 modified the interactive library so that it can run on Luogu.
For of the data, it holds that and .
There are 10 test groups in total, with .
For each group, is respectively $10,100,1000,2000,5000,10000,12500,15000,17500,20000$.
The cost limit for all data is .
Each test group is worth points.
Translated by ChatGPT 5