답안 #145566

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
145566 2019-08-20T12:02:21 Z shashwatchandra Bob (COCI14_bob) C++17
24 / 120
1000 ms 25684 KB
/*input
5 3
2 2 2
2 2 1
1 1 1
2 1 2
1 2 1
*/
#include<bits/stdc++.h>
using namespace std;

#define int long long
#define pb push_back
#define REP(i,n)for(int i = 0;i < n;i++)
#define RE(i,n) for(int i = 1;i <= n;i++)
#define f first
#define s second
#define pii pair<int,int> 

const int N = 1001;
int a[N][N];
int eq[N][N];
int seg[4*N];
int lazy[4*N];
bool zero[4*N];
int n,m;

#define child 2*node
#define mid (l+r)/2

inline void pushdown(int node,int l,int r,bool wow = 1){
	if(zero[node]){
		seg[node] = 0;
		lazy[node] = 0;
		if(l != r){
			zero[child] = 1;
			zero[child+1] = 1;
			if(wow){
				pushdown(child,l,mid,0);
				pushdown(child+1,mid+1,r,0);
			}
		}
		zero[node] = 0;	
	}
	if(wow and l!= r){
		pushdown(child,l,mid);
		pushdown(child+1,mid+1,r);
	}
}

void assign(int node,int l,int r,int start,int end){
	pushdown(node,l,r);
	if(start > r or l > end)return;
	if(start <= l and r <= end){
		zero[node] = 1;
		pushdown(node,l,r);
		return;
	}
	assign(child,l,mid,start,end);
	assign(child+1,mid+1,r,start,end);
	seg[node] = seg[child]+seg[child+1];
}

void add(int node,int l,int r,int start,int end){
	pushdown(node,l,r);
	if(lazy[node] != 0){
		seg[node] += (r-l+1)*lazy[node];
		if(l != r){
			lazy[child] += lazy[node];
			lazy[child+1] += lazy[node];
		}
		lazy[node] = 0;
	}
	if(start > r or l > end)return;
	if(start <= l and r <= end){
		lazy[node]++;
		seg[node] += (r-l+1)*lazy[node];
		if(l != r){
			lazy[child] += lazy[node];
			lazy[child+1] += lazy[node];
		}
		lazy[node] = 0;
		return;
	}
	add(child,l,mid,start,end);
	add(child+1,mid+1,r,start,end);
	seg[node] = seg[child]+seg[child+1];
}

void print(int node,int l,int r){
		cout << "FOR : " << node << " " << l << " " << r << endl;
		cout << seg[node] << " " << lazy[node] << " " << zero[node] << endl;
		if(l == r)return;
		print(child,l,mid);
		print(child+1,mid+1,r);
	
}



void solve(){
	cin >> n >> m;
	RE(i,n){
		RE(j,m)cin >> a[i][j];
	}
	RE(i,n){
		int ind = 1;
		RE(j,m){
			if(a[i][j] != a[i][ind]){
				ind = j;
			}
			eq[i][j] = ind;
		}
	}
	int ans = 0;
	RE(col,m){
		RE(row,n){
			if(a[row][col] != a[row-1][col]){
				assign(1,1,m,1,m);
			}
			if(eq[row][col] != 0)assign(1,1,m,1,eq[row][col]-1);
			//for(int i = 1;i < eq[row][col];i++)seg[i] = 0;
			add(1,1,m,eq[row][col],col);
			ans += seg[1];
		}
	}
	cout << ans;
}

signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1094 ms 8828 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1048 ms 9208 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1037 ms 9336 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1057 ms 9336 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1045 ms 19192 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1048 ms 24708 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1062 ms 25592 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1040 ms 25684 KB Time limit exceeded
2 Halted 0 ms 0 KB -