hdu 6406Taotao Picks Apples 锛?018 Multi-University Training Contest 81010锛夛紙浜屽垎锛屽墠缂€鍜岋級
案头见蠹鱼,犹胜凡俦侣。这篇文章主要讲述hdu 6406Taotao Picks Apples 锛?018 Multi-University Training Contest 81010锛夛紙浜屽垎锛屽墠缂€鍜岋級相关的知识,希望能为你提供帮助。
鏍囩锛?a href='http://www.mamicode.com/so/1/ota' title='ota'>ota
鍋囪
problem
濂界殑
space
its
tao
鏆村姏
int
閾炬帴锛歨ttp://acm.hdu.edu.cn/showproblem.php?pid=6406
鎬濊矾锛?/p>鏆村姏锛岄澶勭悊涓変釜鍓嶇紑鍜岋細銆?,n銆戞瀛愪細琚憳鎺夛紝1鍒板綋鍓嶇偣鐨勬渶澶у€硷紝1鍒板綋鍓嶇偣琚憳鎺夌殑妗冨瓙鐨勬暟閲忥紝鐒跺悗鎴戜滑鏋氫妇淇敼p鐐归€犳垚鐨勬墍鏈夊奖鍝嶏紝锛?/p>
1锛屽亣濡傛柊杈撳叆鐨勭偣姣斿師鍏堢殑鐐圭殑鍊兼洿澶э紝閭d箞鎴戜滑瀵逛慨鏀瑰悗p杩欎釜鐐圭殑鍊煎拰銆?,p-1銆戠殑鏈€澶у€煎叧绯昏繘琛屽垎鏋愶紝涔熷氨鏄垎鏋愬墠鍗婃鐨勫奖鍝嶏細锛?锛夊鏋減鐐瑰ぇ浜?-p-1鐨勬渶澶у€肩殑鏃跺€欐垜浠洿鎺ュ埄鐢ㄥ墠缂€鍜孫(1)寰楀埌銆?锛宲-1銆戞湁澶氬皯涓瀛愯鎽樻帀锛岀劧鍚庡姞涓婂綋鍓嶈繖涓€傦紙2锛夊鏋減鐐瑰皬浜庣瓑浜庛€?锛宲-1銆戠殑鏈€澶у€兼椂锛屽鍓嶅崐娈靛拰鍚庡崐娈甸兘涓嶄細閫犳垚褰卞搷锛岀洿鎺ヨ緭鍑洪澶勭悊鐨勫埌鐨勩€?锛宯銆戠殑鍊煎氨濂戒簡锛涚劧鍚庢垜浠垎鏋愬悗鍗婃鐨勫奖鍝嶏細锛?锛夊鏋減鐐瑰ぇ浜庛€?,p-1銆戠殑鏈€澶у€硷紝閭d箞鍚庡崐娈典腑鍙湁琚憳鎺夌殑妗冨瓙浼氬彈鍒板奖鍝嶏紝鎴戜滑鐩存帴浜屽垎鎵惧埌銆恜+1,n銆戜腑琚憳鎺夌殑妗冨瓙鐨勫€煎ぇ浜庤淇敼鍚庣殑鍊糲鐨勪笅鏍囷紝鍑忎竴涓嬶紝灏卞緱鍑轰簡锛屽悗鍗婃浼氳鎽樻帀鐨勬瀛愪腑鏈夊嚑涓湪p鐐硅淇敼鍚庝緷鏃ч渶瑕佹憳鎺夛紝灏嗗悗鍗婃鐨勫€间笌鍓嶅崐娈电殑鍊煎姞璧锋潵灏卞ソ浜嗐€傦紙2锛夊鏋減鐐瑰皬浜庣瓑浜庛€?,p-1銆戠殑鏈€澶у€硷紝閭d箞鍚庡崐娈典笉閫犳垚褰卞搷锛?/p>【hdu 6406Taotao Picks Apples 锛?018 Multi-University Training Contest 81010锛夛紙浜屽垎锛屽墠缂€鍜岋級】2.鍋囧鏂拌緭鍏ョ殑鐐瑰皬浜庣瓑浜庡師鍏堢殑鐐瑰€硷紝渚濇棫瀵逛慨鏀瑰悗p杩欎釜鐐圭殑鍊煎拰銆?,p-1銆戠殑鏈€澶у€艰繘琛屽垎鏋愶細鍏堝垎鏋愬墠鍗婃鐨勫奖鍝嶏細锛?锛夊鏋減鐐瑰ぇ浜?-p-1鐨勬渶澶у€肩殑鏃跺€欐垜浠洿鎺ュ埄鐢ㄥ墠缂€鍜孫(1)寰楀埌銆?锛宲-1銆戞湁澶氬皯涓瀛愯鎽樻帀锛岀劧鍚庡姞涓婂綋鍓嶈繖涓€傦紙2锛夊鏋減鐐瑰皬浜庣瓑浜庛€?,p-1銆戠殑鏈€澶у€硷紝閭d箞杩欎釜鐐逛緷鏃у鍓嶅崐娈典笉閫犳垚褰卞搷锛屽墠鍗婃鐨勫€肩瓑浜庛€?,p-1銆戜腑琚憳鎺夌殑妗冨瓙鐨勬暟閲忥紝
鎺ヤ笅鏉ュ氨鏄渶闅惧緱鍚庡崐娈电殑璁ㄨ锛?/p>涔嬪墠澶勭悊杩欓噷鎬濊矾琚崱浜嗗緢涔咃細锛?锛夊鏋減鐐瑰ぇ浜?-p-1鐨勬渶澶у€?/p>鍥犱负褰撳墠鐐瑰彉灏忎簡锛屽鍚庨潰鐐归€犳垚鐨勫奖鍝嶅氨鏄細鎽樻帀涓€浜涘師鍏堜笉浼氳鎽樼殑妗冨瓙锛岄偅涔堟€庝箞纭畾杩欎簺妗冨瓙鐨勫叿浣撴槸閭d簺鍛紵 瀹為檯涓婃垜浠彲浠ユ帹鍑猴紝杩欎簺澶氭憳鐨勬瀛愰兘鏄湪1鍒板綋鍓嶅潗鏍囦腑鍙皬浜巔鐨勬暟锛屽洜涓鸿繖浜涙暟鏄綋p鍙樺皬浜嗘墠澶氬嚭鏉ョ殑锛岄偅涔堜粬浠湪1鍒板綋鍓嶇偣鑲畾鏄彧灏忎簬p鐐癸紝閭d箞鎴戜滑鎶婂畠鍔犲埌鍓嶄竴缁翠负p鐨剉ecvector鏁扮粍閲岋紝鑷充簬鎬庝箞鎵惧埌杩欎簺鍊硷紝鎴戜滑鍙澶氱淮鎶や竴涓浜屽ぇ鍊煎氨鍙互浜嗭紝杩欎簺绗簩澶у€煎氨鏄湁鍙兘浼氬鎽樼殑妗冨瓙銆傚綋p鐐逛负鍘熷厛浼氳鎽樼殑妗冨瓙鏃舵垜浠瀛樺湪v[p]閲岀殑鍊艰繘琛屼簩鍒嗘壘鍒版瘮p鍊间慨鏀瑰悗澶х殑閭d簺鍊硷紝涔熷氨鏄悗鍗婃鏂板鐨勫€硷紝鍐嶅姞涓婂師鍏堝氨瑕佹憳寰楀€笺€?/p>锛?锛?濡傛灉灏忎簬绛変簬鐨勮瘽锛屼緷鏃т笉閫犳垚褰卞搷锛岀洿鎺ュ幓鍓嶇紑鍜屽氨濂戒簡
3锛屽亣璁捐緭鍏ョ殑鐐瑰拰鍘熸潵鐨勭偣鍊间竴鏍凤紝鐩存帴鍓嶇紑鍜屽彇
杩欐牱涓€鍏辨槸浜旂涓昏鎯呭喌锛?涓ょ鐢ㄤ簩鍒哋(logn)锛屽彟澶栦笁绉嶇洿鎺ュ墠缂€鍜孫(1)锛岀◢寰绠椾究鍙煡涓嶄細瓒呮椂銆傛渶鍚庤窇浜?05ms锛岄鐩粰浜?000mS,绠楄窇鐨勫緢蹇殑浜嗭紝 灏辨槸瀹炵幇鏈夌偣澶嶆潅锛屽簲璇ヨ繕鏈夋洿濂界殑瑙f硶锛屼笉杩囨瘮璧涚殑鏃跺€欐病鎯抽偅涔堝锛岀洿鎺ユ毚鍔涜幗杩囧幓浜嗭紝杩樺ソ杩囦簡瑕佷笉鏀逛唬鐮佽鏀瑰埌鍚愩€傘€俀AQ
瀹炵幇浠g爜锛?/p>
#include< bits/stdc++.h> using namespace std; const int M = 1e5+10; struct node{ int id,val; }; vector< int> v[M]; int a[M],ans[M],maxx[M],b[M],arr[M]; int main() { int t,n,q,p,c; scanf("%d",& t); while(t--){ scanf("%d%d",& n,& q); for(int i = 1; i < = n; i ++){ scanf("%d",& a[i]); } node mx,mx1; mx.val = 0; mx1.val = 0,mx.id = 0,mx1.id = 0; int cnt = 0,num = 0; maxx[0] = 0; for(int i = 1; i < = n; i ++){ if(mx.val < a[i]){ mx1.val = mx.val; mx1.id = mx.id; mx.val = a[i]; mx.id = i; b[cnt++] = a[i]; num++; } else if(mx1.val < a[i]){ mx1.val = a[i]; mx1.id = i; v[mx.id].push_back(a[i]); } maxx[i] = mx.val; ans[i] = num; } while(q--){ scanf("%d%d",& p,& c); int sum = 0; if(c > a[p]){ if(c > maxx[p-1]){ sum ++; sum += ans[p-1]; int kk =upper_bound(b,b+cnt,c) - b; if(kk != cnt) sum += cnt-kk; } else sum = ans[n]; } else if(c == a[p])sum = ans[n]; else{ if(c > maxx[p-1]) sum++,sum += ans[p-1]; else sum += ans[p-1]; if(a[p] == maxx[p]){ int kk = upper_bound(v[p].begin(),v[p].end(),c)-v[p].begin(); sum += v[p].size() - kk; int kk1 =upper_bound(b,b+cnt,a[p]) - b; if(kk1 != cnt)sum += cnt-kk1; } else sum = ans[n]; } printf("%d ",sum); } for(int i = 0; i < = n; i ++){ maxx[i] = 0; ans[i] = 0; v[i].clear(); } for(int i = 0; i < = cnt; i ++)b[i] = 0; } return 0; }
推荐阅读
- Appium 之处理首次启动手机App时的系统权限弹框
- Android 8.0 的部分坑及对应解决方法
- Android Studio设置HTTP代理(可用)
- 解决 AutoMapper ProjectTo 不起作用的问题
- GPSAndroid O平台如何设置SUPL地址
- HBuilder打包成app状态栏的颜色问题
- iptables/netfilter????tcp_wrapper
- WPF中的Application类。
- 安卓9.0内测的背后,是上万App开发者半年来的适配优化