QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#763412 | #6990. Maximum Element In A Stack | hejinming983282# | AC ✓ | 1848ms | 23496kb | C++23 | 2.2kb | 2024-11-19 20:08:23 | 2024-11-19 20:08:23 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef unsigned int uint;
typedef unsigned long long ull;
// Define the maximum possible n per test case
const int MAX_N = 5000000;
// Global array for stack_max
uint stack_max_arr[5000000];
int main(){
int T;
scanf("%d", &T);
for(int test_case=1; test_case <= T; test_case++){
// Read n, p, q, m, SA, SB, SC
int n;
uint p, q, m;
uint SA, SB, SC;
scanf("%d %u %u %u %u %u %u", &n, &p, &q, &m, &SA, &SB, &SC);
int stack_size =0;
ull y =0;
for(int i=1; i<=n; i++){
// First rng61() for operation decision
SA ^= (SA << 16);
SA ^= (SA >> 5);
SA ^= (SA << 1);
uint t = SA;
SA = SB;
SB = SC;
SC ^= t ^ SA;
uint op_rng = SC;
uint op_decision = op_rng % (p + q);
if(op_decision < p){
// PUSH operation, need to generate value
SA ^= (SA << 16);
SA ^= (SA >> 5);
SA ^= (SA << 1);
t = SA;
SA = SB;
SB = SC;
SC ^= t ^ SA;
uint val_rng = SC;
uint v = (val_rng % m) +1;
uint new_max;
if(stack_size >0){
if(v > stack_max_arr[stack_size -1]){
new_max = v;
}
else{
new_max = stack_max_arr[stack_size -1];
}
}
else{
new_max = v;
}
stack_max_arr[stack_size] = new_max;
stack_size++;
}
else{
// POP operation
if(stack_size >0){
stack_size--;
}
// else do nothing
}
// After operation, get a_i
uint a_i = (stack_size >0) ? stack_max_arr[stack_size -1] : 0;
y ^= ((ull)i) * ((ull)a_i);
}
printf("Case #%d: %llu\n", test_case, y);
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3908kb
input:
2 4 1 1 4 23333 66666 233333 4 2 1 4 23333 66666 233333
output:
Case #1: 19 Case #2: 1
result:
ok 6 tokens
Test #2:
score: 0
Accepted
time: 1848ms
memory: 23496kb
input:
50 4517095 246207717 129392923 441603524 942728 992841 320179 4883008 979693707 717210919 267533974 538438 765353 649825 4981827 625477340 920244804 829171195 801038 761537 742107 4625632 24097542 355414336 317606343 552471 950939 286008 4329907 611729265 611729261 507265569 538624 912919 45550 4259...
output:
Case #1: 1627504186044056 Case #2: 184905552315092 Case #3: 3897202679177730 Case #4: 2228259106250060 Case #5: 1929538272937274 Case #6: 66931260278883 Case #7: 869898314972282 Case #8: 1995905642617582 Case #9: 3732298107313100 Case #10: 1334344664684530 Case #11: 1949914155224287 Case #12: 630994...
result:
ok 150 tokens