# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
812499 |
2023-08-07T08:58:28 Z |
Khizri |
게임 (IOI13_game) |
C++17 |
|
590 ms |
256004 KB |
#include "game.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define INF 1e18
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define OK cout<<"Ok"<<endl;
#define MOD (ll)(1e9+7)
int a,b;
long long gcd(long long X, long long Y) {
long long tmp;
while (X != Y && Y != 0) {
tmp = X;
X = Y;
Y = tmp % Y;
}
return X;
}
struct st{
vector<vector<ll>>tree;
vector<vector<ll>>arr;
int n,m;
void give_size(int x,int y){
n=x,m=y;
tree.resize(4*n+5,vector<ll>(4*m+5));
arr.resize(n+5,vector<ll>(m+5));
}
void buildy(int nodex,int lx,int rx,int nodey,int ly,int ry){
if(ly==ry){
if(lx==rx){
tree[nodex][nodey]=arr[lx][ly];
}
else{
tree[nodex][nodey]=gcd(tree[2*nodex][nodey],tree[2*nodex+1][nodey]);
}
}
else{
int my=(ly+ry)/2;
buildy(nodex,lx,rx,2*nodey,ly,my);
buildy(nodex,lx,rx,2*nodey+1,my+1,ry);
tree[nodex][nodey]=gcd(tree[nodex][2*nodey],tree[nodex][2*nodey+1]);
}
}
void buildx(int node,int l,int r){
if(l!=r){
int mx=(l+r)/2;
buildx(2*node,l,mx);
buildx(2*node+1,mx+1,r);
}
buildy(node,l,r,1,l,m);
}
void updatey(int nodex,int lx,int rx,int nodey,int ly,int ry,int x,int y,ll val){
if(ly==ry){
if(lx==rx){
tree[nodex][nodey]=val;
}
else{
tree[nodex][nodey]=gcd(tree[nodex*2][nodey],tree[nodex*2+1][nodey]);
}
}
else{
int my=(ly+ry)/2;
if(y<=my){
updatey(nodex,lx,rx,2*nodey,ly,my,x,y,val);
}
else{
updatey(nodex,lx,rx,2*nodey+1,my+1,ry,x,y,val);
}
tree[nodex][nodey]=gcd(tree[nodex][2*nodey],tree[nodex][2*nodey+1]);
}
}
void updatex(int node,int l,int r,int x,int y,ll val){
if(l!=r){
int mx=(l+r)/2;
if(x<=mx){
updatex(2*node,l,mx,x,y,val);
}
else{
updatex(2*node+1,mx+1,r,x,y,val);
}
}
updatey(node,l,r,1,1,m,x,y,val);
}
ll query_y(int nodex,int nodey,int l,int r,int ql,int qr){
if(l>r) return 0;
if(l>qr||r<ql) return 0;
if(ql<=l&&r<=qr) return tree[nodex][nodey];
int my=(l+r)/2;
ll left=query_y(nodex,nodey*2,l,my,ql,qr);
ll right=query_y(nodex,nodey*2+1,my+1,r,ql,qr);
return gcd(left,right);
}
ll query_x(int node,int l,int r,int ql,int qr,int qly,int qry){
if(l>r) return 0;
if(l>qr||r<ql) return 0;
if(ql<=l&&r<=qr){
return query_y(node,1,1,m,qly,qry);
}
int mx=(l+r)/2;
ll left=query_x(2*node,l,mx,ql,qr,qly,qry);
ll right=query_x(2*node+1,mx+1,r,ql,qr,qly,qry);
return gcd(left,right);
}
};
st tree;
void init(int R, int C) {
a=R,b=C;
tree.give_size(R,C);
tree.buildx(1,1,a);
}
void update(int P, int Q, long long K) {
tree.updatex(1,1,a,P+1,Q+1,K);
}
long long calculate(int P, int Q, int U, int V) {
return tree.query_x(1,1,a,P+1,U+1,Q+1,V+1);
}
/*
g++ game.cpp grader.c ; .\a.exe
2 3 9
1 0 0 20
1 0 2 15
1 1 1 12
2 0 0 0 2
2 0 0 1 1
1 0 1 6
1 1 1 14
2 0 0 0 2
2 0 0 1 1
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
1620 KB |
Output is correct |
3 |
Correct |
1 ms |
1576 KB |
Output is correct |
4 |
Correct |
1 ms |
296 KB |
Output is correct |
5 |
Correct |
2 ms |
1620 KB |
Output is correct |
6 |
Correct |
1 ms |
1620 KB |
Output is correct |
7 |
Correct |
1 ms |
296 KB |
Output is correct |
8 |
Runtime error |
99 ms |
256000 KB |
Execution killed with signal 9 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
571 ms |
162232 KB |
Output is correct |
5 |
Correct |
428 ms |
162128 KB |
Output is correct |
6 |
Correct |
506 ms |
159576 KB |
Output is correct |
7 |
Correct |
548 ms |
159292 KB |
Output is correct |
8 |
Correct |
474 ms |
159628 KB |
Output is correct |
9 |
Correct |
590 ms |
159288 KB |
Output is correct |
10 |
Correct |
559 ms |
158944 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
1620 KB |
Output is correct |
3 |
Correct |
1 ms |
1620 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
1620 KB |
Output is correct |
6 |
Correct |
2 ms |
1620 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Runtime error |
103 ms |
256000 KB |
Execution killed with signal 9 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
1620 KB |
Output is correct |
3 |
Correct |
2 ms |
1580 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
1620 KB |
Output is correct |
6 |
Correct |
1 ms |
1620 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Runtime error |
102 ms |
256000 KB |
Execution killed with signal 9 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
1620 KB |
Output is correct |
3 |
Correct |
2 ms |
1620 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
1620 KB |
Output is correct |
6 |
Correct |
2 ms |
1620 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Runtime error |
129 ms |
256004 KB |
Execution killed with signal 9 |
9 |
Halted |
0 ms |
0 KB |
- |