회원가입
로그인
Toggle navigation
문제
문제
전체 문제
문제 출처
단계별로 풀어보기
알고리즘 분류
추가된 문제
문제 순위
문제
푼 사람이 한 명인 문제
아무도 못 푼 문제
최근 제출된 문제
최근 풀린 문제
랜덤
출처
ICPC
Olympiad
한국정보올림피아드
한국정보올림피아드시․도지역본선
전국 대학생 프로그래밍 대회 동아리 연합
대학교 대회
카카오 코드 페스티벌
Coder's High
ICPC
Regionals
World Finals
Korea Regional
Africa and the Middle East Regionals
Europe Regionals
Latin America Regionals
North America Regionals
South Pacific Regionals
문제집
대회
채점 현황
게시판
그룹
더 보기
재채점 기록
블로그
도움말
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
시간초과 억까좀 그만
13547번 - 수열과 쿼리 5
kangjijoon
7달 전
0
시간초과 억까좀 살려주세요
진짜 ㄱ ㅐ 같습니다 ㅜㅜㅜ
#include "iostream" #include "algorithm" using namespace std; typedef struct Node{ int first,second,index,k; bool operator<(Node &rhs){ return (first / k < rhs.first / k) || ((first / k == rhs.first / k) && (second < rhs.second)); } }Node; int N,Q,k,s,e,m; int sqrt(){ s = 1,e = N; while(e - s > 1){ m = (s+e) / 2; if(m * m == N) return m; if(m * m > N) e = m; else s = m; } if(e*e == N) return e; return s; } int Count[1000001] = {0,},cnt = 0; int main(){ ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> N; k = sqrt(); int v[N+1]; for(int i=1;i<=N;++i) cin >> v[i]; cin >> Q; Node query[Q]; int res[Q]; for(int i=0;i<Q;++i) {cin >> query[i].first >> query[i].second;query[i].index = i;query[i].k = k;} sort(query,query+Q-1); s = query[0].first; e = query[0].second; for(int i = s;i <= e;++i) if(!(Count[v[i]]++)) ++cnt; res[query[0].index] = cnt; for(int i = 1;i<Q;++i){ while(s < query[i].first) if(!(--Count[v[s++]])) --cnt; while(s > query[i].first) if(!(Count[v[--s]]++)) ++cnt; while(e < query[i].second) if(!(Count[v[++e]]++)) ++cnt; while(e > query[i].second) if(!(--Count[v[e--]])) --cnt; res[query[i].index] = cnt; } for(int i = 0;i<Q;++i) cout << res[i] << '\n'; }
zenith82114
7달 전
0
10만의 절반인 5만을 제곱하면 25억이며 이는 int의 범위를 넘는 값입니다.
댓글을 작성하려면
로그인
해야 합니다.
kangjijoon 7달 전
시간초과 억까좀 살려주세요
진짜 ㄱ ㅐ 같습니다 ㅜㅜㅜ