From 836baf841273defd1710c79bd9ce064accb42160 Mon Sep 17 00:00:00 2001 From: Adithya Date: Mon, 23 Oct 2023 09:30:23 +0530 Subject: [PATCH] Added q300.cpp --- .vscode/c_cpp_properties.json | 38 +++++++++--------- .vscode/launch.json | 24 +++++++++++ .vscode/settings.json | 76 ++++++++++++++++++++++++++++++----- q300.cpp | 30 ++++++++++++++ 4 files changed, 139 insertions(+), 29 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 q300.cpp diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index fa39c58..32374bd 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -1,21 +1,21 @@ { - "configurations": [ - { - "name": "Win32", - "includePath": [ - "${workspaceFolder}/**" - ], - "defines": [ - "_DEBUG", - "UNICODE", - "_UNICODE" - ], - "windowsSdkVersion": "10.0.19041.0", - "compilerPath": "C:/msys64/mingw64/bin/gcc.exe", - "cStandard": "c17", - "cppStandard": "c++17", - "intelliSenseMode": "windows-gcc-x64" - } - ], - "version": 4 + "configurations": [ + { + "name": "windows-gcc-x86", + "includePath": [ + "${workspaceFolder}/**" + ], + "defines": [ + "_DEBUG", + "UNICODE", + "_UNICODE" + ], + "windowsSdkVersion": "10.0.19041.0", + "compilerPath": "C:/MinGW/bin/gcc.exe", + "cStandard": "${default}", + "cppStandard": "${default}", + "intelliSenseMode": "windows-gcc-x86" + } + ], + "version": 4 } \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..d234ed7 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,24 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "C/C++ Runner: Debug Session", + "type": "cppdbg", + "request": "launch", + "args": [], + "stopAtEntry": false, + "externalConsole": true, + "cwd": "c:/Users/adith/OneDrive/Desktop/Hacktoberfest2023/leetcode-journey", + "program": "c:/Users/adith/OneDrive/Desktop/Hacktoberfest2023/leetcode-journey/build/Debug/outDebug", + "MIMode": "gdb", + "miDebuggerPath": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 007a1c5..cf6c41f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,11 +1,67 @@ { - "files.exclude": { - "**/*.exe": true, - - }, - "files.associations": { - "*.tcc": "cpp", - "random": "cpp", - "iostream": "cpp" - } - } \ No newline at end of file + "files.exclude": { + "**/*.exe": true + }, + "files.associations": { + "*.tcc": "cpp", + "random": "cpp", + "iostream": "cpp" + }, + "C_Cpp_Runner.msvcBatchPath": "", + "C_Cpp_Runner.cCompilerPath": "gcc", + "C_Cpp_Runner.cppCompilerPath": "g++", + "C_Cpp_Runner.debuggerPath": "gdb", + "C_Cpp_Runner.cStandard": "", + "C_Cpp_Runner.cppStandard": "", + "C_Cpp_Runner.useMsvc": false, + "C_Cpp_Runner.warnings": [ + "-Wall", + "-Wextra", + "-Wpedantic", + "-Wshadow", + "-Wformat=2", + "-Wcast-align", + "-Wconversion", + "-Wsign-conversion", + "-Wnull-dereference" + ], + "C_Cpp_Runner.msvcWarnings": [ + "/W4", + "/permissive-", + "/w14242", + "/w14287", + "/w14296", + "/w14311", + "/w14826", + "/w44062", + "/w44242", + "/w14905", + "/w14906", + "/w14263", + "/w44265", + "/w14928" + ], + "C_Cpp_Runner.enableWarnings": true, + "C_Cpp_Runner.warningsAsError": false, + "C_Cpp_Runner.compilerArgs": [], + "C_Cpp_Runner.linkerArgs": [], + "C_Cpp_Runner.includePaths": [], + "C_Cpp_Runner.includeSearch": [ + "*", + "**/*" + ], + "C_Cpp_Runner.excludeSearch": [ + "**/build", + "**/build/**", + "**/.*", + "**/.*/**", + "**/.vscode", + "**/.vscode/**" + ], + "C_Cpp_Runner.useAddressSanitizer": false, + "C_Cpp_Runner.useUndefinedSanitizer": false, + "C_Cpp_Runner.useLeakSanitizer": false, + "C_Cpp_Runner.showCompilationTime": false, + "C_Cpp_Runner.useLinkTimeOptimization": false, + "C_Cpp_Runner.msvcSecureNoWarnings": false +} \ No newline at end of file diff --git a/q300.cpp b/q300.cpp new file mode 100644 index 0000000..23ec33d --- /dev/null +++ b/q300.cpp @@ -0,0 +1,30 @@ +class MaxBIT { // One-based indexing + vector bit; +public: + MaxBIT(int size) { + bit.resize(size + 1); + } + int get(int idx) { + int ans = 0; + for (; idx > 0; idx -= idx & -idx) + ans = max(ans, bit[idx]); + return ans; + } + void update(int idx, int val) { + for (; idx < bit.size(); idx += idx & -idx) + bit[idx] = max(bit[idx], val); + } +}; +class Solution { // 16 ms, faster than 72.16% +public: + int lengthOfLIS(vector& nums) { + int BASE = 10001; + MaxBIT bit(20001); + for (int x : nums) { + int subLongest = bit.get(BASE + x - 1); + bit.update(BASE + x, subLongest + 1); + } + return bit.get(20001); + } +}; +// question : https://leetcode.com/problems/longest-increasing-subsequence/ \ No newline at end of file