답안 #4724

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
4724 2013-12-22T15:07:17 Z tncks0121 사다리꼴 (balkan11_trapezoid) C++
40 / 100
139 ms 8636 KB
#include <stdio.h> 
#include <stdlib.h> 
#include <string.h> 
#include <memory.h> 
#include <math.h> 
#include <assert.h> 
#include <stack> 
#include <queue> 
#include <map> 
#include <set> 
#include <algorithm> 
#include <string> 
#include <functional> 
#include <vector> 
#include <deque> 
#include <utility> 
#include <bitset> 
#include <limits.h>  

using namespace std; 
typedef long long ll; 
typedef unsigned long long llu; 
typedef double lf;
typedef unsigned int uint;
typedef long double llf;
typedef pair<int, int> pii;

const int N_ = 100005;

int N;

struct Segment {
	int a, b, t;
	Segment (int a = 0, int b = 0, int t = 0): a(a), b(b), t(t) { }
	bool operator< (const Segment &s) const { return a != s.a ? a < s.a : b > s.b; }
};

Segment D[N_+N_];
int DN;
int X[N_+N_];

const int MOD = 30013;
const int LEAF = 131072*2;

struct Node {
	int c, p;
	Node (int c = 0, int p = 0): c(c), p(p) { }
	void apply (Node t) {
		if(t.c > c) c = t.c, p = t.p;
		else if(t.c == c) p = (p + t.p) % MOD;
	}
} Tree[N_+N_+LEAF], Table[N_];

void update (int x, int c, int p) {
	x += LEAF;
	if(Tree[x].c < c) Tree[x] = Node(c, p);
	while(x >>= 1) {
		Node &nd = Tree[x];
		Node &l = Tree[x+x], &r = Tree[x+x+1];
		if(l.c == r.c) nd = Node(l.c, (l.p + r.p) % MOD);
		else if(l.c > r.c) nd = l;
		else nd = r;
	}
}

Node get (int en) {
	int st = LEAF+1; en += LEAF;
	Node ret;
	while(st <= en) {
		if((st & 1) == 1) ret.apply(Tree[st]);
		if((en & 1) == 0) ret.apply(Tree[en]);
		st = (st+1) >> 1;
		en = (en-1) >> 1;
	}
	return ret;
}

int main() {
	int i, j, k;

	scanf("%d", &N);
	for(i = 1; i <= N; i++) {
		int a,b,c,d; scanf("%d%d%d%d", &a, &b, &c, &d);
		D[++DN] = Segment(a, c, -i); X[DN] = b;
		D[++DN] = Segment(b, d,  i); X[DN] = d;
	}

	sort(D+1, D+DN+1);
	sort(X+1, X+DN+1);
	int XN = unique(X+1, X+DN+1) - (X+1);

	for(i = 1; i <= DN; i++) {
		Segment &s = D[i];
		s.b = lower_bound(X+1, X+XN+1, s.b) - X;
		if(s.t < 0) { // left
			Table[-s.t] = get(s.b - 1);
			++Table[-s.t].c;
		}else {
			update(s.b, Table[s.t].c, Table[s.t].p);
		}
	}
	
	printf("%d %d\n", get(DN).c, get(DN).p);
	return 0;
}

Compilation message

trapezoid.cpp: In function 'int main()':
trapezoid.cpp:79:9: warning: unused variable 'j' [-Wunused-variable]
  int i, j, k;
         ^
trapezoid.cpp:79:12: warning: unused variable 'k' [-Wunused-variable]
  int i, j, k;
            ^
trapezoid.cpp:81:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
                 ^
trapezoid.cpp:83:49: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int a,b,c,d; scanf("%d%d%d%d", &a, &b, &c, &d);
                                                 ^
# 결과 실행 시간 메모리 Grader output
1 Partially correct 0 ms 8636 KB Partially correct
2 Partially correct 3 ms 8636 KB Partially correct
3 Partially correct 3 ms 8636 KB Partially correct
4 Partially correct 0 ms 8636 KB Partially correct
5 Partially correct 3 ms 8636 KB Partially correct
6 Partially correct 6 ms 8636 KB Partially correct
7 Partially correct 3 ms 8636 KB Partially correct
8 Partially correct 6 ms 8636 KB Partially correct
9 Partially correct 13 ms 8636 KB Partially correct
10 Partially correct 23 ms 8636 KB Partially correct
11 Partially correct 29 ms 8636 KB Partially correct
12 Partially correct 66 ms 8636 KB Partially correct
13 Partially correct 86 ms 8636 KB Partially correct
14 Partially correct 96 ms 8636 KB Partially correct
15 Partially correct 103 ms 8636 KB Partially correct
16 Partially correct 119 ms 8636 KB Partially correct
17 Partially correct 126 ms 8636 KB Partially correct
18 Partially correct 96 ms 8636 KB Partially correct
19 Partially correct 129 ms 8636 KB Partially correct
20 Partially correct 139 ms 8636 KB Partially correct