QOJ.ac
QOJ
ID | 提交记录ID | 题目 | Hacker | Owner | 结果 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|
#1200 | #763412 | #6990. Maximum Element In A Stack | hejinming983282 | hejinming983282 | Failed. | 2024-11-19 20:08:55 | 2024-11-19 20:08:55 |
详细
Extra Test:
Invalid Input
input:
1 0 0 0 0 0
output:
result:
FAIL Integer parameter [name=n] equals to 0, violates the range [1, 5000000] (stdin, line 2)
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 |
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;
}